We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

how to prevent user for inserting data after maximum lenth

Using jquery and gridview

I want to prevent user from entering data more that 50 character

so while inserting content user keyboard should not allow to insert data means key press event should not work

so after maximum no of character entered by user. user should not allowed to insert data.

I do not want to fire event on click on save


2) I wan to fire required field validation on tab button.

  for example when I click on first text box after insert value, when click on tab button required field should fire.
In current scenario when I insert data and after click on save button on tool bar it fires required field validation 
but i want to fire required field validation on tab button.











1 Reply

IR Isuriya Rajan Syncfusion Team August 17, 2015 04:00 PM UTC

Hi Bharat,

For easy communication purposes, we have presented the response in a table format as below:

                                    Query

                                   Response

1)I want to prevent user from entering data more that 50 character

so while inserting content user keyboard should not allow to insert data means key press event should not work

so after maximum no of character entered by user. user should not allowed to insert data.

I do not want to fire event on click on save

You can achieve your requirement by using this actionComplete event.It will trigger every action completed in the Grid.

In code given below, we have bound  keypress event for all input fields. But you can also bind this event to specific columns.

function actionComplete(args) {

if (args.requestType == "add" || args.requestType == "beginedit")             

            $("#"+this._id+"EditForm").find('.e-ejinputtext').keypress(function (e) {

                    if (this.value.length > 3) {

                        // check the condition for keypressed and disable the key press event

                        return false

                    }

                });

        }

2) I wan to fire required field validation on tab button.

  for example when I click on first text box after insert value, when click on tab button required field should fire.

In current scenario when I insert data and after click on save button on tool bar it fires required field validation 

but i want to fire required field validation on tab button

We can set validation for a  grid as per our requirement.Based on the requirement we have to set  validationRules .

By default behavior of the jquery validator, it can’t fire the validation error on tab key press validation. So we have to set manually validation on onfoucout event. By using this event we can enable the validation for tab key press.

Here’s the code that demonstrates  how we can enable the validation condition for tab key press.

$(function () {

           $.validator.setDefaults({ onfocusout: function (element) { $(element).valid() } });

       })      

</script>

Please refer this documentation link for how we can use validation for grid columns.

Online Sample Link: Validation

We have created a downloadable sample for this:

Sample Link: http://www.syncfusion.com/downloads/support/directtrac/general/New_Compressed_(zipped)_Folder_(2)1940114524.zip

Online sample: Sample

Please try the above sample and let us know if it helps. Please let us know if we have missed anything and we will gladly assist.

Regards,

Isuriya R



Loader.
Live Chat Icon For mobile
Up arrow icon