如何强制输入字段值验证?

时间:2018-06-03 17:54:36

标签: javascript jquery html angularjs

我正在编写一个脚本,将信息填入网站的表单然后提交。 我按document.getElementById("input_field_id").value = "value";输入要输入的数据字段;提交之前的表单必须通过AngularJS代码进行验证,但是当数据在字段中弹出但未经验证时,我该如何强制执行?

代码示例:https://plnkr.co/edit/VuLLF7FRc3kg6gFj3EB3?p=preview                                                                               / code不是我的,我用它作为我的问题的一个例子/

1 个答案:

答案 0 :(得分:1)

通过使用class AuthScreen extends Component { render() { const shouldRenderLogin = props => props.mode === MODE.LOGIN; const shouldRenderSignup = props => props.mode === MODE.SIGNUP; const withLogin = withEither(shouldRenderLogin, () => ( <Login onPressSignup={() => this.props.onChangeAuthMode(MODE.SIGNUP)} onTryLogin={this.props.onTryLogin} /> )); const withSignUp = withEither(shouldRenderSignup, () => ( <Text>Implement Signup Page</Text> )); const withConditionalRendering = compose(withLogin, withSignUp); const LoginForm = withConditionalRendering(() => ( <Text>Unrecognized Login Mode</Text> )); return ( <ImageBackground source={backgroundImage} style={styles.backgroundImage}> <KeyboardAvoidingView behavior="padding" style={styles.container}> <StatusBar barStyle="light-content" /> <View style={styles.innerContainer}> <LoginForm mode={this.props.authMode} /> </View> </KeyboardAvoidingView> </ImageBackground> ); } },您正在执行Angular范围之外的操作,因此您的应用程序无法识别这些更改。您需要在控制器内执行此操作,如下所示:

export const withEither = (conditionRenderFn, EitherComponent) => (Component) => (props) => conditionRenderFn(props) ? <EitherComponent {...props}/> : <Component {...props} />