Angularjs验证基于多个下拉列表ID [英] Angularjs validations based on multiple dropdown id's

查看:122
本文介绍了Angularjs验证基于多个下拉列表ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我使用的是angularjs和webapi。在输入字段中,我有一个下拉频道,一个文本来自金额1,另一个下拉条件(< =,> =),一个文本框表示金额,另外一个文本框表示费用金额。该场景是当我选择一个频道并从值输入并且为其存储数据库的值和费用金额。如果我从金额和相同渠道ID的金额中输入另一个金额,则金额应为先前输入金额的下一个金额。而且金额总是大于金额。我希望上述场景中每个频道的angularjs验证。请帮帮我。我尝试了以下代码,但它无法正常工作。



我尝试过的方法:



here i am using angularjs and webapi. in the entering fields i have one dropdown for channels, one text for from amount one, another dropdown for conditions(<=,>=), one text box for to amount, one more text box for fee amount. The scenario is when i select one channel and enterin from value and to value and fee amount its storing database. if i enter another from amount and to amount for same channel id, the from amount should next value of previous entered to amount. and also from amount always greater than to amount. i want angularjs validations for each channel for above scenario. Please help me out. I tried for the below code but its not working properly.

What I have tried:

$scope.SaveFixedFee = function () {

            $scope.validate = false;
            if ($scope.AddFixedfeeForm.$valid) {
                angular.forEach($scope.lsteComfixedfeelist, function (value, key) {
                    if (value.ChannelId == $scope.channelid) {
                        if (value.Condition.indexOf("=") != -1) {


                            if (($scope.frmamt >= value.FromAmount && $scope.frmamt <= value.ToAmount) || ($scope.toamt >= value.FromAmount && $scope.toamt <= value.ToAmount)) {
                                alert("Please check the from and to amount");
                                $scope.validate = true;
                            }
                        }
                        else {
                            if (($scope.frmamt > value.FromAmount && $scope.frmamt < value.ToAmount) || ($scope.toamt > value.FromAmount && $scope.toamt <= value.ToAmount)) {
                                alert("Please check the from and to amount");
                                $scope.validate = true;
                            }                        }
                        if (value.Condition.indexOf(">") != -1) {
                            if ((parseInt($scope.frmamt) - 1) != parseInt(value.ToAmount)) {
                                $scope.validate1 = true;
                            }
                        }
                        else {
                            if (parseInt($scope.frmamt) != parseInt(value.ToAmount)) {
                                $scope.validate2 = true;
                            }
                        }
                    }
                })
                if ($scope.validate) {
                    alert("false");
                    return false;
                }
                if ($scope.validate1) {
                    alert("false1");
                    return false;
                }
                if ($scope.validate2) {
                    alert("false2");
                    return false;
                }
                if ((parseInt($scope.frmamt) > parseInt($scope.toamt)) || (parseInt($scope.frmamt) >= parseInt($scope.toamt))) {

                    alert("from amount should less than the to amount");
                    return false;
                }


                //if ($scope.validate()) {
                //    return false;
                //}
                var Requestboy = {
                    'ChannelId': $scope.channelid,
                    'FromAmount': $scope.frmamt,
                    'ToAmount': $scope.toamt,
                    'FixedFee': $scope.feeamt,
                    'Condition': $scope.condition,
                    'CreatedBy': $scope.LoginRoleId

                }

                $http.post(serviceBasePath + '/api/Product/addFixedFee', Requestboy).then(function (response) {
                    if (response.data.indexOf("Successfully") != -1) {
                        alert("Successfully Updated");
                        $state.reload();
                    }
                    else {
                        alert(response.data);
                        return false;
                    }

                }, function (error) {
                    alert("Something Went Wrong");
                    return false;
                })
            }


        }

推荐答案

范围。 SaveFixedFee = function (){
scope.SaveFixedFee = function () {


scope.validate = false ;
if
scope.validate = false; if (


scope.AddFixedfeeForm。
scope.AddFixedfeeForm.


这篇关于Angularjs验证基于多个下拉列表ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆