I currently have a select (drop down) column validated so users are forced to select an option when editing and adding records:
$col[“editrules”] = array(“custom”=>true,”custom_func”=>”function(value,label){return dropdown_validation(value,label);}”);
This uses the Javascript code:
function dropdown_validation(value, label) {
if(value.length > 0) {
return [true,””];
} else {
return [false, label+” field must be selected”];
}
}
This works fine for single record edits, but while bulk editing the validation code is still triggered for fields that don’t need changing during the bulk edit.
Is there an easy way of modifying the above to only trigger during bulk editing if ” – Empty – ” has been selected in the respective field?
Thanks.
After a bit of trial and error I’ve managed to create a usable solution, probably not the best but basically involves checking the dialog title to determine if it’s the bulk editor or not.
function dropdown_validation(value, label, bulkeditcount) {
if(jQuery("#edithdlist1").find("span").text() != "Bulk Edit"){
if(value.length > 0) {
return [true,""];
} else {
return [false, label+" field must be selected"];
}
} else {
if(value != "-"){
return [true,""];
} else {
return [false, label+" field is required"];
}
}
}
Thanks for sharing. For others, here ‘edithdlist1’ … list1 is your grid id being set in render(“list1”).
One other simple options was to create 2 columns with same name. Show one for normal operations but hidden on bulk edit. And other hidden for normal operations and shown for bulk edit.
With each column you can set them true/false accordingly.
$col[“show”] = array(“list”=>true, “add”=>true, “edit”=>true, “view”=>true, “bulkedit”=>true);