Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
515
Regarding custom validation when one field is dependent on other.
posted

Hello everyone,

So,  I have created a grid and populated it with data. So i have two doubts. 

1) how to target a particular field for custom validation. I have used it here but i couldnt understand how its getting the element.

2) suppose i have two columns marks and image. So i want to apply a validation that if marks is greater than 60 and less than 100 then image field is mandatory else it is optional . can you help me like how to do that.

Heres my code,

<script>
$(function () {
$("#grid").igGrid({
primaryKey: "id",
renderCheckboxes: true,
autoGenerateColumns: false,
updateUrl: "/Student/put/",
width: "100%",

columns: [
{ headerText: "Student ID", key: "id", dataType: "number", width: "15%" },
{ headerText: "Student Name", key: "name", dataType: "string", width: "30%" },
{ headerText: "Marks", key: "marks", dataType: "number", width: "30%" },
{
headerText: "Image",
key: "imagepath",
dataType: "string",
width: "15%",
template: "<img src='${imagepath}' width='50' height='50' />"
},
{ headerText: "Subject", key: "subject", dataType: "string", width: "15%" }
],
dataSourceUrl: "/Student/Data12",
dataSource: "/Student/Data",


features: [
{
name: "Selection",
mode: "row",
multipleSelection: true
},
{
name: "RowSelectors",
enableCheckBoxes: true,
enableRowNumbering: true
},
{
name: "GroupBy"
},
{
name :"Paging",
type:"local",
pageSize : 7
},

{
name: "Filtering",
columnSettings: [
{
columnKey: "selectColumn",
allowFiltering: false
}
]
},
{
name: "Sorting",
type: "remote",
// sortUrlKey: 'sort',
// sortUrlKeyAscValue: 'asc',
// sortUrlKeyDescValue: 'desc'
},
{
name: "Updating",
enableAddRow: true,
editMode: "row",
validation: true,
enableDeleteRow: true,
rowAdded: function (evt, ui) {
// Custom logic to execute when a row is added
console.log("Event arguments (ui):", ui);
console.log("Row data:", ui.rowId);
console.log(typeof (ui.values));
},
columnSettings: [
{
columnKey: "id",
readonly: true

},
{
columnKey: "name",
editorType: "text",
validation: true,
editorOptions: {

validatorOptions:
{
required: {
errorMessage: "You must enter a value to submit."

},
custom: function(ui,evt){
var validator = $("#grid").igGridUpdating("editorForKey", "name").data("igValidator").element;
console.log(validator);
if (ui == "rohit")
$(validator).igValidator("option", "errorMessage", "cant enter name rohit");
return false;
return true;

}

}
}
}
]
}
]
});
var editor = $("#grid").igGridUpdating("editorForKey", "id");
alert(editor);

$("#savechanges").on("click", function () {
alert("Save button clicked");
// Save changes when the button is clicked
$("#grid").igGrid("saveChanges");
});
});

</script>

Parents
No Data
Reply
  • 0
    Offline posted
    I have a field. And If a certain value is entered into this field I want to require that a few other fields are not null. I'm trying to figure this out. Cross field validation is the use of multiple fields in your dataset to sanity check the integrity of your data. For example in our flights dataset, this could be summing economy,  human benchmark   business and first class values and making sure they are equal to the total passengers on the plane.Field validation is an automated process of ascertaining that each field contains the correct value before the form is accepted. The concept is straightforward. Does the phone number field contain a phone number? Does the email address field have all the parts that an email address needs to have?
Children
No Data