Is there any 'native' form tag form to identify change to the original state of a form?

2

Assuming a form was loaded with 10 text fields with a value of 1, and the user changed one of these to 0.

When submitting the form, is there something 'native' that identifies that it has had a change in the value of its fields?

I want this to differentiate the trigger of an event when the user did or did not make any changes to the open editing form.

Currently I use a very extensive process for this, when submitting, I get all the variants of the input, I look for the data that was in the bank, I compare field by field to know if there was modification and to define what the event will be triggered, I think There should be a more efficient way, but I could not find it.

I wanted something native or one that comes naturally because of the reason:

I do not write events for a submission, I have a framework with abstract event that makes the whole process, from validation, sealing masks, concatenation and submission of any form (provided the form has also been generated by the framework ), the solution must be something that I can convert into something universal, otherwise I can not implement it in the framework.

Rendering example:

$campo = $VIDB_input->field('campo')->mask('mascara_que_eu_quiser')->type('text')->validator('validacao_que_eu_quiser')->additional_classnames('classnames_que_eu_quiser')->value($data['valor_trazido_do_bd'])->datepicker(false)->dateranger(false)->input(0);
$form_group = $VIDB_form_group->group_cols(12)->input($campo)->input_cols(12)->label('Campo: ')->label_cols(12)->form_group(0);
$submit = $VIDB_button->color('primary')->content('Salvar edições')->addicionalClassnames('pull-right')->event('submit_fake_form|caller|geralOperationalCompanies|save_edited|sectorGeral|closeClosestModalOnSuccess|json|primary-modal|SweetAlertByResponse')->event_post_content(null)->type('submit')->button(0);
$form = $VIDB_fake_form->classnames()->content($form_group.$submit)->form(0);

This code, does the whole process of:

Rendering the form, concatenating the data, dropping the mask in the input, validating client-side real-time, validating server-side and responding and submitting the form, I would need to somehow also make this comparison somewhat global.

    
asked by anonymous 20.09.2017 / 16:21

2 answers

5

You can compare 2 arrays of objects in the submission, ie the result of the database with which you will send example ...

When submitting submit serialize form and convert to json

var formdata = $("#myform").serializeArray();
var data = {};
$(formdata ).each(function(index, obj){
    data[obj.name] = obj.value;
});

make an ajax request to and return the bank result in json with php

ai just compare the two

if(JSON.stringify(data) == JSON.stringify(banco)) console.log('iguais');

Depending on the condition you upgrade or not ...

It is worth remembering that the name of the inputs in the form should hit the name of the column in the database.

    
20.09.2017 / 16:56
3

I'm not sure, but you can try the onChange event. If that does not work, you can use onChange in the input. View

Look at the example:

<script>
function myfunction(f){
	alert(f)
}
</script>

<form onchange="myfunction(this)"/>
  <input type="test"/>
  <input type="test"/>
  <input type="test"/>
</form>

The event occurs when the field loses focus. Then the change occurs.

    
20.09.2017 / 16:27