x-editable resetting fields

2019-07-07 04:49发布

i have the following html/php code (php tag ommited)

$user = array(
    'name' => Null,
    'address' => Null
);  

<div id="user">
    <a href="#"  id="cust_name" data-type="text"
         data-pk="'.$user['ag_id'].'" title="Enter customer name">'.$user['name'].'</a>
    <a href="#"  id="cust_addr" data-type="text"
         data-pk="'.$user['ag_id'].'" title="Enter customer address">'.$user['address'].'</a>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" id="ResetButton">Reset</button>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-primary" id="SaveButton"
             data-dismiss="modal">Save changes</button>
    </div>
</div>

could you please complete my resetbutton script, the purpose is to assign null to cust_name and cust_addr after the click.. here's the script

<script>
    $.fn.editable.defaults.mode = 'inline';

    $(function(){
        $('#user a').editable({
           url: 'post.php' 
        });
    });

    $("#SaveButton").click(function() {
        $.ajax({
            url: 'db.php',
            type: 'POST',
            data: {}
        });
    });

    $('#ResetButton').click(function() {
        // $('#cust_name').editable('setValue', null); // did not worked            
        // didn't worked even i added class="myeditable" in my <a> tag
        /*
        $('.myeditable').editable('setValue', null)
           .editable('option', 'pk', null)
           .removeClass('editable-unsaved');
        */
    });

</script> 

1条回答
看我几分像从前
2楼-- · 2019-07-07 05:23

This seemed to work.

http://jsfiddle.net/U33kT/

I'm not sure the difference, except that I chose all editables (JS line 6):

$('#user a').editable('setValue', null);

But, I tried with single items:

$('#cust_name').editable('setValue', null);

and it seemed to work as well.

Hope this helps.

查看更多
登录 后发表回答