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
close icon

how to apply validation rules in the event "actionBegin"

Hi.

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





3 Replies

SA Saravanan Arunachalam Syncfusion Team June 7, 2017 01:25 PM UTC

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. 



LC Luis Carlos replied to Saravanan Arunachalam June 8, 2017 03:03 PM UTC

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.


SA Saravanan Arunachalam Syncfusion Team June 9, 2017 08:50 AM UTC

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. 


Loader.
Up arrow icon