简体   繁体   English

通过js使angular1表单变脏

[英]making an angular1 form dirty via js

I am sending form data to a login/password and then wanting to click the submit button, the problem is with the form validation requiring the form to be dirty. 我正在将表单数据发送到登录名/密码,然后想要单击“提交”按钮,问题在于表单验证要求表单变脏。 And I am directly assigning the values which means the form is not considered dirty and modified. 而且我直接分配值,这意味着该表单不被认为是脏的和被修改的。 I have tried focus but that doesn't seem to work either. 我已经尝试过聚焦,但这似乎也不起作用。 The submit button won't appear because it isn't validated. 提交按钮不会显示,因为它未经验证。

document.getElementById("email").focus(); 
document.getElementById("password").focus();
var e = document.getElementById("email"); 
e.value = 'currentEmployee@email.com';
var p = document.getElementById("password");
p.value = 'currentEmployee.password';
var osbut = document.getElementById("loginForm"); osbut.submit();

I am injected a script via a chrome extension, running it as a content.js script. 我通过chrome扩展程序注入了一个脚本,并将其作为content.js脚本运行。 Any help is appreciated. 任何帮助表示赞赏。

Just set In Controller Form as valid. 只需在“控制器表单”中将其设置为有效即可。 For example: 例如:

$scope.formName.$valid=true;

See examples that dispatch change event, or alternatively change the elements via document.execCommand 'insertText' – wOxxOm 查看分配变更事件的示例,或者通过document.execCommand'insertText'– wOxxOm更改元素

This worked perfectly. 这工作得很好。 I just wanted to close out the question. 我只是想结束这个问题。 -Hunter -猎人

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

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