X-Editable gets the value of an unedited input field

Currently, I have a form that I use as a page for viewing / editing contacts. Instead of sending values ​​each time a single field is edited, I try to use the save button, which would compile the values ​​object from the form and send them to the database. The problem I'm having is that when I try to get the value of an input field, if that input field has not been edited, the return value will be "

$('#view-contact-first-name').editable("getValue") 

I tried to view the x-editables documentation and tried to use the savenochange: true parameter, but that also did not solve my problem. Does anyone know what I can do wrong. (If necessary, can send more code)

 $('#view-contact-first-name').editable({
        type: 'text',
        name: 'FirstName',
       // url: '',
        emptytext: "Enter First Name",
        savenochange: true,
        validate: {
            view_contact_first_name: function (v) { if (v == '') return 'Required field!' }
        },
        display: function () {
            $(this).text(contact.FirstName);
        }
    });
+4
1

, , x-.

x-editable , .

, :

HTML

<div id="containAllEditable"><!-- lots of x-editable inputs inside --></div>

JS

$('#containAllEditable .editable').editable({
    type: 'text',
    name: 'FirstName',
   // url: '',
    emptytext: "Enter First Name",
    savenochange: true,
    validate: {
        view_contact_first_name: function (v) { if (v == '') return 'Required field!' }
    },
    display: function () {
        $(this).text(contact.FirstName);
    },
}).on('save',function(){
    /*
    *  Event triggered when save is successful
    */
    var dataJson;
    $('#containAllEditable .editable').each(function(){
         /* We build a JSON list of all input found in the div */
         dataJson[$(this).attr('data-name')] = $(this).editable('getValue');
    });

    /* Do your ajaxy stuff and save all the form variables */
    $.ajax({
         url:'url/to/saveform',
         data: dataJson,
    })
});
+3

Source: https://habr.com/ru/post/1570892/


All Articles