Hi Abu!
How can I make a JS Validation when I add a record, the sample demo shows how to add it when you do a inline edit but what about when you add?
Hope you can help me out.
Hello,
It works for both add and edit.
If you are facing any issue, please email back screenshot and issue details.
To use form validation on both edit/add you need following code:
$grid["edit_options"]["beforeSubmit"] = "function(post,form){ return validate_form_once(post,form); }";
$grid["add_options"]["beforeSubmit"] = "function(post,form){ return validate_form_once(post,form); }";
$g->set_options($grid);
This will call your JS function on add dialog as well.
This is my code but it only works when I edit a record, inlineEdit. How can I add this when I add a new record?
function validate_form_once(post,form)
{
var str=[];
if (parseInt(post.alto) < parseInt(post.ancho))
str[str.length] = "- El ancho no puede ser más grande que el alto";
str = str.join("<br>");
if (str.length == 0)
return [true,""];
else
return [false,"Error:<br>"+str];
}
// enable form validation in inline edit
jQuery.extend(jQuery.jgrid.inlineEdit, {
beforeSaveRow: function (o,rowid) {
data = [];
jQuery(".editable").each(function(){ data[jQuery(this).attr('name')] = jQuery(this).val(); });
ret = validate_form_once(data);
if (!ret[0])
jQuery.jgrid.info_dialog(jQuery.jgrid.errors.errcap,'<div class="ui-state-error" style="text-align:left;padding:5px">'+ ret[1] +'</div>',
jQuery.jgrid.edit.bClose,{buttonalign:'right'});
jQuery("#info_dialog").abscenter();
return ret[0];
}
});