Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to submit a hidden field and control its value with x-editable?

inside the document of X-editable, we can create a new record, but how to edit an existing record, and post its name and email fields as well as its id =1(this id not changed) to the backend?

<table>
    <thead><th>id</th><th>name</th><td>email</th></thead>
    <tbody>
        <tr><td><span>1</span></td><td><span class='myeditable'>name</span></td><td><span class='myeditable'>[email protected]</span></td></tr>
    </tbody>
</table>

$('.myeditable').editable({
    type: input,
    url: '/edituser'
});

$('#save-btn').click(function() {
    $('.myeditable').editable('submit', {
        url: '/edituser',
        ajaxOptions: {
            dataType: 'json' //assuming json response
        },
        success: function(data, config) {
            if(data && data.id) { //record created, response like {"id": 2}
            },
            error: function(errors) {
            }
    });
});
like image 525
bwlee Avatar asked Nov 02 '22 18:11

bwlee


1 Answers

I used Angular-xeditable to do this, but the idea is the same I think.

I added a hidden span to my table and gave it an e-name. ng-show sets display:none, which I think is just what you need to do as well.

          <span
            editable-text="journalEntry._id"
            e-name="_id" 
            e-form="rowform"
            ng-show="false">
          </span>
like image 137
Michael Cole Avatar answered Nov 09 '22 13:11

Michael Cole