* client: validate form on load

This commit is contained in:
Ildar Kamalov 2019-04-17 16:24:18 +03:00 committed by Simon Zolin
parent f76b7c3d94
commit ceabad0fd0
2 changed files with 168 additions and 155 deletions

View File

@ -1,4 +1,4 @@
import React, { Fragment } from 'react'; import React, { Component, Fragment } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Field, reduxForm, formValueSelector } from 'redux-form'; import { Field, reduxForm, formValueSelector } from 'redux-form';
@ -61,7 +61,17 @@ const renderInterfaces = (interfaces => (
}) })
)); ));
let Settings = (props) => { class Settings extends Component {
componentDidMount() {
const { web, dns } = this.props.config;
this.props.validateForm({
web,
dns,
});
}
render() {
const { const {
handleSubmit, handleSubmit,
handleChange, handleChange,
@ -73,7 +83,7 @@ let Settings = (props) => {
interfaces, interfaces,
invalid, invalid,
config, config,
} = props; } = this.props;
const { const {
status: webStatus, status: webStatus,
can_autofix: isWebFixAvailable, can_autofix: isWebFixAvailable,
@ -225,12 +235,14 @@ let Settings = (props) => {
<Controls invalid={invalid} /> <Controls invalid={invalid} />
</form> </form>
); );
}; }
}
Settings.propTypes = { Settings.propTypes = {
handleSubmit: PropTypes.func.isRequired, handleSubmit: PropTypes.func.isRequired,
handleChange: PropTypes.func, handleChange: PropTypes.func,
handleAutofix: PropTypes.func, handleAutofix: PropTypes.func,
validateForm: PropTypes.func,
webIp: PropTypes.string.isRequired, webIp: PropTypes.string.isRequired,
dnsIp: PropTypes.string.isRequired, dnsIp: PropTypes.string.isRequired,
config: PropTypes.object.isRequired, config: PropTypes.object.isRequired,
@ -249,7 +261,7 @@ Settings.propTypes = {
const selector = formValueSelector('install'); const selector = formValueSelector('install');
Settings = connect((state) => { const SettingsForm = connect((state) => {
const webIp = selector(state, 'web.ip'); const webIp = selector(state, 'web.ip');
const webPort = selector(state, 'web.port'); const webPort = selector(state, 'web.port');
const dnsIp = selector(state, 'dns.ip'); const dnsIp = selector(state, 'dns.ip');
@ -270,4 +282,4 @@ export default flow([
destroyOnUnmount: false, destroyOnUnmount: false,
forceUnregisterOnUnmount: true, forceUnregisterOnUnmount: true,
}), }),
])(Settings); ])(SettingsForm);

View File

@ -94,6 +94,7 @@ class Setup extends Component {
interfaces={interfaces} interfaces={interfaces}
onSubmit={this.nextStep} onSubmit={this.nextStep}
onChange={this.handleFormChange} onChange={this.handleFormChange}
validateForm={this.handleFormChange}
handleAutofix={this.handleAutofix} handleAutofix={this.handleAutofix}
/> />
); );