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.
Unfortunately, activation email could not send to your email. Please try again.

how to apply validation rules in the event "actionBegin"

Thread ID:

Created:

Updated:

Platform:

Replies:

130813 Jun 5,2017 06:41 AM Jun 9,2017 04:50 AM JavaScript 3
loading
Tags: ejGrid
Luis Carlos
Asked On June 5, 2017 06:41 AM

Hi.

How can I assign a validation rule and validation message to a specific cell (InputTextBox) in the event "actionBegin" ???





Saravanan Arunachalam [Syncfusion]
Replied On June 7, 2017 09:25 AM

Hi Luis, 
Thanks for contacting Syncfusion’s support. 
We understood from your query, you need to add a validation rule dynamically for a particular column and we can achieve this requirement by using columns method of Grid control. Please refer to the below api reference link. 
And hence could you please provide the following details? 
1.       Which scenario you need to add validation for a particular column? 
2.       Do you need to add a validation rule for a column when initially render the Grid? 
3.       Please provide clear details of your requirement. 
Regards, 
Saravanan A. 


Luis Carlos
Replied On June 8, 2017 11:03 AM

Hi Luis, 
Thanks for contacting Syncfusion’s support. 
We understood from your query, you need to add a validation rule dynamically for a particular column and we can achieve this requirement by using columns method of Grid control. Please refer to the below api reference link. 
And hence could you please provide the following details? 
1.       Which scenario you need to add validation for a particular column? 
2.       Do you need to add a validation rule for a column when initially render the Grid? 
3.       Please provide clear details of your requirement. 
Regards, 
Saravanan A. 


Hi again.

Maybe I didn't explain very well. Let me try it again.

When I would like to edit a row (three cells of the follow image), I have two differents cases.

1º Case.
The first cell (Categoría) is required.

2º Case.
First two cells (Categoría and Descripción) is required.



Therefore, I would like to use the event "actionBegin" in order to change (required/not required) the parameters of the second cell.

How can I do it ??

I hope you understand my query. Thank you again.

Best regards,
Luis Carlos.

Saravanan Arunachalam [Syncfusion]
Replied On June 9, 2017 04:50 AM

Hi Luis, 
We have achieved your requirement “dynamically change the validation message based on certain condition” by using custom validation feature of ejGrid that can be refer from the below code example and reference links. 
$(function () { 
            var str; 
            $.validator.addMethod("customvalidation", function (value, element, params) { 
                var fCellval =  $(element.closest("td")).prev().find("input").val(); 
                var sCellval = element.value; 
                if((fCellval != "" && sCellval != "")) 
                    return true; 
                return false; 
            }, function(params, element) { 
                var val =  $(element.closest("td")).prev().find("input").val(); 
                var val1 = element.value; 
                //Change the message dynamically 
                if (val != "" && val1 == "") 
                    str = "Customer ID is required"; 
               else if(val == "" && val1 != "") 
                   str = "First Cell value is required"; 
 
                else  
                    str = "Order ID and Customer ID is required"; 
                 return str; 
            }); 
 
            $("#Grid").ejGrid({ 
                columns: [ 
                              . . .                                                     { field: "CustomerID", headerText: 'Customer ID', width: 90, validationRules: { customvalidation: true } }, 
                            . . . 
                                                                                 
                ] 
            }); 
        }); 
 
We have also created a sample that can be refer from the below jsplayground link. 
Regards, 
Saravanan A. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;