cancel
Showing results for 
Search instead for 
Did you mean: 

Restrict a Text field to input more than 10 characters using "Type System"

Aisurya
Participant
0 Kudos

Hi All,

I am trying to restrict for a Text field for entering more than 10 characters in the UI , using "Type System".

Below is the piece of code from Demo kit:


// creating of a float type with 2 format options and one constraint

     var oFloat = new sap.ui.model.type.Float(

       {

          minFractionDigits: 2,

          maxFractionDigits: 2      

       },

       {

          maximum: 10

       }

     );

var oText = new sap.ui.commons.TextField({value: {path: "/sliderValue", type: oFloat}});

oText.bindValue("/sliderValue", oFloat);

But the Text Field is allowing more than 10 characters .

Please help me in this..

Accepted Solutions (0)

Answers (1)

Answers (1)

surendra_pamidi
Contributor
0 Kudos

Hi Aisurya,

Use below one..

var oText = new sap.ui.commons.TextField({


                     maxLength:10,


                     value: {path: "/sliderValue", type: oFloat}


                }); 

Regards,

Surendra.

Aisurya
Participant
0 Kudos

Hi, Thanks for your reply .. So what is the use of the below line of code : " value: {path: "/sliderValue", type: oFloat} "  Thanks Aisurya.

jmoors
Active Contributor
0 Kudos

In your first example you are configuring that the maximum value can be 10.00 on the data type, which you can then implement the validation handlers to determine if the format is correct or display error message etc.

attachFormatError

attachParseError

attachValidationError

attachValidationSuccess

The example that Surendra has provided is setting the maximum length of characters on the TextField control, will restrict to 10 characters rather an a particular value.

Jason

surendra_pamidi
Contributor
0 Kudos

Hi Aisurya,

It is for length only. But it is not working if you use maximum in Float. Might be library problem. But if you want you can use above..

jmoors
Active Contributor
0 Kudos

The value: {path: "/sliderValue", type: oFloat} code binds the control to the model data.

Setting the length will not prevent entering of invalid characters/format or validating the actual value.

Here is a working exampl of the validation.

http://jsbin.com/EKEgAneh/1/edit?html,output

Jason