问题标签 [angularjs-ng-form]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
1974 浏览

angularjs - angualrjs,使用 ng-repeat 查找重复的输入验证,嵌套在表单下的 ng-form

我试图找到在文本框中输入的重复值,该值检查 ng-change 上的每个输入值。然后显示消息“sos 编号匹配”。尝试了这个,但仍然按顺序对列表数据进行排序。 结果,到目前为止,我没有成功发送常规消息jsfiddle 。以下是代码。:

html代码:

ng-change 方法:

0 投票
0 回答
689 浏览

angularjs - 带有保存按钮验证的 ngform 表单不起作用 angular.js

我有一个动态生成字段的表单,我正在使用ng-form它。该表单有一个ng-repeat输入字段,主表单有一个“保存”按钮。

即,当输入字段之一脏且有内容时,应启用保存按钮,否则应禁用

这是我的 HTML 代码:

因此,为了在表单最初加载时禁用我的保存按钮,我应该如何使用ng-form礼物来验证它?当其中一个输入字段中有一些文本时,应启用保存。不确定我们如何在表单保存按钮中ng-disabled处理ng-form

0 投票
2 回答
177 浏览

angularjs - 使用 angularjs 创建动态表单

所以我用 angularjs 创建动态表单。发送表单后,我将其从数组中删除。但是由于某些奇怪的原因,表单验证规则以某种方式“坚持”到下一个表单。例如。我发送第一个表格,如果第三个表格有有效答案,则第二个表格现在得到验证,依此类推,如果第 4 个表格有有效答案,则第 3 个表格将有效。这可能是什么原因?

这几乎是我所拥有的基础知识的精简代码

还有我的发送功能:

顺便说一句,我将 ng-form="" 作为 item.ItemForm 所以我可以在按下发送所有按钮时通过项目访问表单,它会检查哪些表单是有效的并且只发送那些表单。如果有不同的或适当的方式来做这件事,我会全神贯注。

0 投票
1 回答
586 浏览

angularjs - AngularJS:以编程方式添加嵌套表单(ngForm)

我有一个特定的问题,我需要在使用 angular 构建的表单中添加嵌套表单。

静态(非编程),我可以执行以下操作:

嵌套表单中的验证错误会使外部表单无效。这正是我需要的。

但我似乎无法通过指令以编程方式执行此操作。在模板中,我有以下内容

我有以下内容:

表单确实被注入 DOM 并且处于无效状态,在 Chrome 元素视图中,我看到了

但外部形式不会失效。加载外部表单时看不到内部表单吗?

我究竟做错了什么?

0 投票
0 回答
61 浏览

javascript - 可以在 Controller 中检查 ng-form

这是第一行

如果我写

我有未定义

我不知道错误在哪里,你能帮我吗?

0 投票
1 回答
25 浏览

javascript - $myform.textinput.$isvalid 不应该为真

在 stuff[] 至少添加了一项之前,整个表单不应有效。当用户在文本框中输入一个值然后单击添加它然后将该值添加到 stuff[] 时,只有在将值添加到 stuff[] 时才应该启用提交按钮。但是,一旦用户在文本框中输入任何内容而不单击添加,因此在 stuff[] 中没有任何内容,它会使表单有效并启用提交按钮。

0 投票
3 回答
726 浏览

angularjs - Why is $timeout needed when dynamically nesting ng-form in Angular to ensure child form links with parent form?

I cannot seem to avoid the need to generate dynamic sub forms in the application I am working on. The sub form is working as expected and the sub form shows $invalid=true when one or more of it's inputs are invalid. The parent form however has $invalid=false.

I have seen people achieve nested forms where invalid sub forms invalidate the parent form, but I can't seem to do it dynamically without wrapping the dynamic compiling of the sub form in a $timeout.

See Plunker HERE

In the above link I have recreated the scenario. I have three forms. The parent form, a sub form created at the same time as the parent form, and a dynamically created sub form.

If you clear the bottom existing sub form's input, it will invalidate the parent form (parent form turns red).

If you clear the top dynamic form's input, it will not invalidate the parent form (parent form remains green).

It will begin to work if you stick the addForm method in a $timeout:

It's great that I have a workaround, but I would like to understand why I need the $timeout and if there is a solution that avoids the use of a $timeout.

0 投票
3 回答
646 浏览

javascript - 带有生成字段的 Ng-repeat 提交表单

我有这个问题,我有一个 ng-repeat,我在其中添加了一些输入字段,并且我想将这些输入的值提交到生成的表单 - 不适用于 ng-model,但我可以通过里面的输入名称获取表单标签。

0 投票
1 回答
526 浏览

angularjs - 通过未命名的 ng-form 元素的角度循环

在我看来,有没有办法遍历未命名的 ng-form 元素?

我的目标是遍历每个 ng-form,然后遍历每个输入。

0 投票
1 回答
59 浏览

javascript - ng 表单依赖于另一个字段的验证

我有一个角度表单,我有两个输入字段,一个用于表单,一个用于电子邮件。

我想要求电子邮件或电话,我该怎么做?

我试图这样做 : ng-reqired="myForm.phone.$invalid",但这似乎不起作用,一旦你输入其中一个字段(并且两者都变得有效),所以即使在你删除输入之后,两个输入仍然有效,(因为一旦phone成为​​有效,email变为有效。

这是我的 JSfiddle:Js Fiddle

我有一个短期解决方案ng-required="myForm.email.$viewValue == ''",但我正在寻找一个更好的解决方案。

因为这只会检查其他字段是否为空,并且我确实想检查它是否有效,例如,当用户使用无效的电子邮件地址时,是否需要电话。