简体   繁体   English

成功提交后清除jeasyui表单字段

[英]Clear jeasyui form fields after successful submit

I'm using a jeasyui form, inside a xoops module, in which I'm trying to clear all the form fields once the data has successfully submitted. 我正在xoops模块中使用jeasyui表单,一旦数据成功提交,我将在其中尝试清除所有表单字段。

I've already consulted this question , but it didn't solve the problem in my case. 我已经咨询了这个问题 ,但是就我而言,它没有解决问题。

My HTML: 我的HTML:

<div class="easyui-panel" title="Capture Reqs" style "width:100%;
max-width:600px; padding:30px 60px;">

    <form action = "captureReqs_Save.php" id ="ff" class = "easyui-form" 
     method ="post" data-options = "novalidate:true">

        <div style="margin-bottom:20px"> Area <br>
        <input id="idArea" class="easyui-combobox" style="width:260px" name="idArea" 
            data-options="
            url:'areasJson.php?idZona=<?php echo $idZone; ?>',
            label:'Area:',
            valueField: 'id',
            textField: 'desc',
            required:true
        ">
        </div>

        <div style="margin-bottom:20px"> Material 
        <input id="IdMaterial" class="easyui-combobox" style="width:100%"
         name="IdMaterial" data-options="
            loader: myloader,
            mode: 'remote',
            valueField: 'code',
            textField: 'desc',
            required:true
        ">

        <div style="margin-bottom:20px"> Qty
            <input class="easyui-textbox" name="quantity" style="width:100%"
             data-options="label:'Qty:',required:true, validType:'number'">
        </div>


        <div style="margin-bottom:20px">            
    </form>

    <div style="text-align:center;padding:5px 0">
        <a href="javascript:void(0)" class="easyui-linkbutton" 
         onClick = "submitForm()" style="width:80px"> Submit</a>

        <a href="javascript:void(0)" class="easyui-linkbutton" 
         onClick = "resetForm()" style = "width:80px"> Clear </a>
    </div>
</div>

Script: 脚本:

<script>
    var myloader = function (param, success, error) {
        var q = param.q || '';
        if (q.length <= 2) {
            return false
        }
        $.ajax({
            url: 'materialJson.php?idArea=' + $('#idArea').combobox('getValue'),
            dataType: 'json',
            data: {
                q: q
            },
            success: function (data) {
                var items = $.map(data, function (item, index) {
                    return {
                        code: item.code,
                        desc: item.desc
                    };
                });
                success(items);
            },
            error: function () {
                error.apply(this, arguments);
            }
        });
    }

    function submitForm() {
        $('#ff').form('submit', {
            onSubmit: function () {
                return $(this).form('enableValidation').form('validate');
            }
        });

    }

    function resetForm() {
        $('#ff')[0].reset();
    }
</script>

Try calling resetForm. 尝试调用resetForm。 I converted to use promise style ajax and added resetForm 我转换为使用Promise风格的ajax并添加了resetForm

var myloader = function (param, success, error) {
    var q = param.q || '';
    if (q.length <= 2) {
        return false
    }
    $.ajax({
        url: 'materialJson.php?idArea=' + $('#idArea').combobox('getValue'),
        dataType: 'json',
        data: {
            q: q
        }
    }).then(function (data) {
        var items = $.map(data, function (item, index) {
            return {
                code: item.code,
                desc: item.desc
            };
        });
        success(items);
    }).fail(function () {
        error.apply(this, arguments);
    });
}

function submitForm() {
    $('#ff').submit(function () {
        if ($(this).form('enableValidation').form('validate')) {
            $.post($(this).attr('action'), $(this).serialize(), function (response) {
                clearForm();
            });
        }
        return false;
    });
}

function resetForm() {
    $('#ff')[0].reset();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM