Validation when adding records

QuestionsValidation when adding records
Alfonso Cabrera asked 8 years ago

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.

4 Answers
Abu Ghufran answered 8 years ago

Hello,

It works for both add and edit.
If you are facing any issue, please email back screenshot and issue details.

Abu Ghufran answered 8 years ago

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.

Alfonso Cabrera answered 8 years ago

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];
}
});

Alfonso Cabrera answered 8 years ago

Thank you!!! Once again.

Your Answer

8 + 1 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?