【问题标题】:Validation DropDownList outside grid网格外的验证 DropDownList
【发布时间】:2019-08-15 03:21:30
【问题描述】:

我有剑道下拉列表和按钮提交。我希望如果用户没有在下拉菜单(位置)中选择任何内容,将会有验证通知用户必须至少在下拉菜单中选择一个位置。然后,如果用户点击了该位置,那么用户就可以提交数据。我使用了一些类似“必需”的方法,但没有用。

HTML

    <input id="dropdown" style="width:200px;" /> 

用于 kendoDropDownList 的 JavaScript(位置)

$("#dropdown").kendoDropDownList({
    optionLabel: "- Select Position -",
    dataTextField: "functionName",
    dataValueField: "hrsPositionID",
    dataSource: {
    transport:{
        read: {
        url:  "./testjson.php",
        type: "POST",
        data: function() {
                return { 
                    method: "getDropdown",
                }
            }
        },
    },
    },  
    change: function(e){
        console.log(this.value());
        // $('#AccountingTree').data('kendoTreeView').homogeneous.read();
        homogeneous1.read();
        homogeneous2.read();
        homogeneous3.read();
        homogeneous4.read();
        homogeneous5.read();
        homogeneous6.read();
        homogeneous7.read();
        homogeneous8.read();
        homogeneous9.read();
        homogeneous10.read();
        homogeneous11.read();
        homogeneous12.read();
        homogeneous13.read();
        homogeneous14.read();
    }   
}).data('kendoDropDownList');
dropdownlist = $("#dropdown").data("kendoDropDownList");

对于上面的下拉列表,我正在使用同质数据(树视图)。

有人对这个问题有任何想法或参考吗?

JavaScript AJAX 调用提交按钮

//AJAX call for button
    $("#primaryTextButton").click(function(){
        if($("#dropdown").data("kendoDropDownList").value() == ""){
            kendo.alert("Please select position.");
        }
    });
    $("#primaryTextButton").kendoButton();
    var button = $("#primaryTextButton").data("kendoButton");
    button.bind("click", function(e) {

    var test = $("#dropdown").val()

    $.ajax({
        url: "../DesignationProgramTemplate/testjson.php",
        type: "POST",
        data: {
                method: "addTemplate" ,
                id: test,
                progid: array
                },

                success: function (response) {
                if(response === "SUCCESS")
                {
                    kendo.alert("Data saved");

                }else
                { 
                    kendo.confirm("Update the data?")
                    .done(function(){
                        $.ajax({
                        type: "POST",
                        url: "../DesignationProgramTemplate/testjson.php",
                        data: {
                                method: "deleteTemplate" ,
                                id: test,
                                progid: array
                                },
                        success: function(){
                            kendo.alert("Data updated");
                        }
                        });
                    });  
                }   
                },
        });
    });

【问题讨论】:

    标签: javascript html


    【解决方案1】:
    When you click the button, just get the value of the kendoDropDownList and do a 
    conditional statement. Hope this helps. Happy Coding ;D
    
            //AJAX call for button
            $("#primaryTextButton").kendoButton();
            var button = $("#primaryTextButton").data("kendoButton");
            button.bind("click", function(e) {
    
            var test = $("#dropdown").data("kendoDropDownList").value();
            if(test == ""){
                    kendo.alert("Please select position.");
            }
            else{
                $.ajax({
                    url: "../DesignationProgramTemplate/testjson.php",
                    type: "POST",
                    data: {
                        method: "addTemplate" ,
                        id: test,
                        progid: array
                    },
                    success: function (response) {
                        if(response === "SUCCESS"){
                            kendo.alert("Data saved");
                        }
                        else{ 
                            kendo.confirm("Update the data?")
                            .done(function(){
                                $.ajax({
                                type: "POST",
                                url: "../DesignationProgramTemplate/testjson.php",
                                data: {
                                        method: "deleteTemplate" ,
                                        id: test,
                                        progid: array
                                        },
                                success: function(){
                                    kendo.alert("Data updated");
                                }
                                });
                            });  
                        }   
                    },
                });
            }
        });
    

    【讨论】:

    • 我已经更新了上面提交按钮的代码。并把你给的代码。但是,输出是 kendo.confim 先出来,然后是警报“请选择位置”。是不是我放错了代码行?
    • 我更新了代码。我之前删除了代码并将其移动到您的代码中并将其包装到 if-else 语句中。
    猜你喜欢
    • 2013-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-07
    相关资源
    最近更新 更多