Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 验证失败时,第一次单击时未形成表单数据对象;仅在第二次单击时_Javascript_Html_Angularjs_Forms - Fatal编程技术网

Javascript 验证失败时,第一次单击时未形成表单数据对象;仅在第二次单击时

Javascript 验证失败时,第一次单击时未形成表单数据对象;仅在第二次单击时,javascript,html,angularjs,forms,Javascript,Html,Angularjs,Forms,我正在使用一个非常简单的表单向我们的API提交一些东西。我使用一个名为I'm just submitting的指令添加了一些表单验证;'“id”和“点”。我遇到了一个奇怪的问题,我在解决这个问题时遇到了很多麻烦,希望能在这里得到一些帮助 表单验证工作正常。如果我在输入字段中输入了一个未通过的值,则无法提交表单并在输入下方显示一条消息,说明出现的原因。但是,如果我删除不正确的输入并输入正确的输入,消息仍然存在。如果我点击提交按钮,消息就会消失。如果我再次单击“提交”按钮,它将提交。但是,我注意到,

我正在使用一个非常简单的表单向我们的API提交一些东西。我使用一个名为I'm just submitting的指令添加了一些表单验证;'“id”和“点”。我遇到了一个奇怪的问题,我在解决这个问题时遇到了很多麻烦,希望能在这里得到一些帮助

表单验证工作正常。如果我在输入字段中输入了一个未通过的值,则无法提交表单并在输入下方显示一条消息,说明出现的原因。但是,如果我删除不正确的输入并输入正确的输入,消息仍然存在。如果我点击提交按钮,消息就会消失。如果我再次单击“提交”按钮,它将提交。但是,我注意到,如果我只按enter键,它会立即提交

我扔了一些console.log在里面,看起来问题在于没有在第一次单击时创建formData对象;只有在第二天。以下是html:

<form name="pointsField">
    <p><input type="number" ng-model="formData.points"
        validation-only-numbers="true"
        validation-field-required="{message:'Points value is required.',value:true}"
        min="0"/></p>
    <p><button class="btn btn-success" type="button" ng-click="updatePoints(pointsField)" ng-disabled="loading">
        <span ng-if="loading"><i class="fa fa-circle-o-notch fa-la fa-spin"></i></span>Update Points
    </button></p>
</form>

如果有人能帮助我,我将永远感激。谢谢大家!

尝试在表单标签中添加
novalidate
,如果不起作用,请不要使用角度ui表单验证,只需使用以下格式进行验证

<form name="pointsField" novalidate>

   <input type="text" id="username" name="username" placeholder="Email Address"
                   ng-model="user.username" autocomplete="off" required >
   <span class="text-danger" ng-show="pointsField.username.$dirty && pointsField.username.$invalid">
                    <span ng-show="pointsField.username.$error.required">Email Address is required</span>
                  </span>


    <button type="submit" class="submit center" ng-disabled="pointsField.$invalid || dataLoading ">

<form>

电子邮件地址是必需的

尝试在表单标签中添加
novalidate
,如果不起作用,请不要使用角度ui表单验证,只需使用以下格式进行验证

<form name="pointsField" novalidate>

   <input type="text" id="username" name="username" placeholder="Email Address"
                   ng-model="user.username" autocomplete="off" required >
   <span class="text-danger" ng-show="pointsField.username.$dirty && pointsField.username.$invalid">
                    <span ng-show="pointsField.username.$error.required">Email Address is required</span>
                  </span>


    <button type="submit" class="submit center" ng-disabled="pointsField.$invalid || dataLoading ">

<form>

电子邮件地址是必需的

尝试添加
$scope.apply()
在何处?我想我以前从未使用过它。在“$scope.updatePoints”的第1行,看看它是否能正常工作。我收到一个错误,提示“$apply已在进行中”。请尝试添加
$scope.apply()
在何处?我想我以前从未使用过它。在“$scope.updatePoints”的第1行,看看它是否能正常工作。我收到一个错误,提示“$apply已在进行中”。谢谢您的帮助!我想我已经弄明白了,看起来这是一个非常恼人的CSS问题。我注意到,如果我点击按钮的顶部,它会在第一时间提交。这就好像错误消息正在按下按钮的可单击区域。感谢您的帮助!我想我已经弄明白了,看起来这是一个非常恼人的CSS问题。我注意到,如果我点击按钮的顶部,它会在第一时间提交。这就好像错误消息按下了按钮的可点击区域。