⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Return modified Rule field to form



Michael Allen Hess
  • profile picture
  • Member

Posted 07 August 2012 - 17:27 PM

Greetings,

I have a custom rule to format a phone number and really need it to update the form after the validation. I just wanted some feed back as to whether or not what I am doing would cause other problems. I haven't checked out all possible field for form types.

In groucery_crud.php

I modify the db_insert_validation( and db_update_validation() methods with the following line:

if($form_validation->run())
{
$validation_result->success = true;

// add this line to return the current $_POST data back to the forms Ajax call.
$validation_result->_field_data = $form_validation->_field_data;
}
else
{
$validation_result->error_message = $form_validation->error_string();
$validation_result->error_fields = $form_validation->_error_array;
}

The above add line returns all the fields that have been established as having rules associated.

Now the javascript change.

Change the file. themes/datatables/js/datatables-edit.js to include the following:

var _field_data = data._field_data;

$.each(_field_data, function() {
$("#crudForm :input[name='" + this.field + "']").val(this.postdata);
});

Place this in the file after the success option of the validation_url ajax call. Right here:


success: function(data){
$("#FormLoading").hide();
if(data.success)
{

var _field_data = data._field_data;

$.each(_field_data, function() {
$("#crudForm :input[name='" + this.field + "']").val(this.postdata);
});

$('#crudForm').ajaxSubmit({


I tried using the callback_before_update but that only took care of the database and not the current form on the screen. This takes care of the form on the screen which also modifies the $_POST data that is sent to the update or insert.