x-editable resetting fields

ぃ、小莉子 提交于 2019-12-10 18:09:54

问题


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:


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.



来源:https://stackoverflow.com/questions/20330541/x-editable-resetting-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!