redux form not updating select field
I am using version 7.2.x and i have fixed the bug with onBlur where it resets teh value of the input. Problem i have now is i can see the state changes and it holds the correct value now but on the gui it does not change the value to show the correct one.
In my reducer i have forms: formReducer,
.
in my component class
const mapStateToProps = state => {
return state;
}
function mapDispatchToProps(dispatch) {
return bindActionCreators(
{
change,
},
dispatch
);
}
const IAMSubnetFormP = reduxForm({
form: 'iamSubnetNewForm', // a unique name for this form
fields: ['type_of_subnet_id', 'subnet_type', 'location', 'security_zone', 'seczone', 'routing_domain', 'zone_confirm', 'subnet_size', 'subnet_confirm', 'iam_addressing_type_id', 'address_space', 'allocation_range', 'new_subnet', 'desc_vr', 'desc_vr_confirm', 'l2env', 'l2env_confirm', 'l3dev', 'l3dev_confirm', 'zone_platform', 'wo', 'iam_network_diagram_id', 'subnet_class', 'project', 'justification', 'project_confirm']
})(IAMSubnetForm);
export default connect(mapStateToProps, mapDispatchToProps)(IAMSubnetFormP);
the select box is rendered as follows
renderTypeOfSubnet() {
let disabled = true;
let data = this.state.data;
console.log(this)
if (Object.keys(this.props.forms.iamSubnetNewForm).length > 0
&& 'values' in this.props.forms.iamSubnetNewForm
&& 'type_of_subnet_id' in this.props.forms.iamSubnetNewForm.values) {
disabled = false;
}
return <Field
label="Please select the type of subnet?"
name="type_of_subnet_id"
component={this.renderSelectField}
type="select" disabled={disabled} data={data}
onBlur={() => {}}
/>;
}
renderSelectField(field) {
const { input, label, type, meta: { touched, error, warning }, data, disabled } = field;
let options = ;
const className = `form-group ${touched && error ? 'has-danger' : ''}`;
const uniqueList = ;
const uniqueListObject = ;
if (input.name == 'type_of_subnet_id') {
this.state.data.map(row => {
if (uniqueList.indexOf(row.subnet_type) === -1) {
uniqueList.push(row.subnet_type);
uniqueListObject.push({ id: row.iam_type_id, text: row.subnet_type, vlan: row.vlan });
}
});
let newuniqueListObject = uniqueListObject.sort(function(a, b) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
options = this.populateOptionsObject(newuniqueListObject);
}
let id = 'select_' + input.name;
if (input.name == 'security_zone' && this.props.forms.iamSubnetNewForm.values.location != '') {
if (this.props.forms.iamSubnetNewForm.values.subnet_type != 'NAT') {
options.unshift(
<option key="" value="">
-- select --
</option>
);
} else {
uniqueListObject.push({ id: 'E1', text: 'N/A' });
options = this.populateOptionsObject(uniqueListObject);
}
} else if (input.name != 'wo' && input.name != 'iam_network_diagram_id' && input.name != 'subnet_class') {
if (this.props.forms.iamSubnetNewForm.values.subnet_type != 'NAT') {
options.unshift(
<option key="" value="">
-- select --
</option>
);
} else if (input.name == 'zone_platform' && this.props.forms.iamSubnetNewForm.values.l3dev_confirm == 'Yes' && this.props.forms.iamSubnetNewForm.values.subnet_type == 'NAT') {
options.unshift(
<option key="N/A" value="N/A">
N/A
</option>
);
} else {
options.unshift(
<option key="" value="">
-- select --
</option>
);
}
} else if (input.name == 'subnet_class' && this.props.forms.iamSubnetNewForm.values.l3dev_confirm == 'Yes' && this.props.forms.iamSubnetNewForm.values.iam_network_diagram_id != '' && this.props.forms.iamSubnetNewForm.values.subnet_type == 'NAT') {
options.unshift(
<option key="N/A" value="N/A">
N/A
</option>
);
}
return (
<div className={className}>
<label className="control-label col-sm-4">{label}</label>
<div className="col-sm-8">
<select
{...input}
onBlur={() => {}}
className="form-control form-control-inline"
type={type}
onChange={event => {
this.resetValues(event);
if (event.target.name == 'type_of_subnet_id') {
if (event.target.value.length > 0) {
let type_of_subnet = _.find(uniqueListObject, { id: event.target.value });
if (type_of_subnet.text == 'NAT') {
this.props.change('security_zone', 'N/A');
this.props.change('seczone', 'E1');
}
this.props.change('subnet_type', type_of_subnet.text);
this.props.change('vlan', type_of_subnet.vlan);
} else {
this.props.change('subnet_type', '');
this.props.change('seczone', '');
this.props.change('security_zone', '');
}
}
this.props.change(event.target.name, event.target.value);
}}
disabled={disabled}
>
{options}
</select>
</div>
<div className="row-fluid">
<div className="col-sm-2" />
<div className="col-sm-10">
{touched &&
((error && (
<span className="text-danger">
<i className="fa fa-exclamation-circle" aria-hidden="true" /> {error}
</span>
)) ||
(warning && (
<span className="text-warning">
<i className="fa fa-question-circle" aria-hidden="true" /> {warning}
</span>
)))}
</div>
</div>
</div>
);
}
It seems like after the change event a re-render is not triggered to update the value on the from end. however it holds the correct value in props
I have replicated issue here
https://codesandbox.io/s/24x376j98n
i need to be able to support multiple forms. for example forms in different components but being rendered on the same view
reactjs redux-form
add a comment |
I am using version 7.2.x and i have fixed the bug with onBlur where it resets teh value of the input. Problem i have now is i can see the state changes and it holds the correct value now but on the gui it does not change the value to show the correct one.
In my reducer i have forms: formReducer,
.
in my component class
const mapStateToProps = state => {
return state;
}
function mapDispatchToProps(dispatch) {
return bindActionCreators(
{
change,
},
dispatch
);
}
const IAMSubnetFormP = reduxForm({
form: 'iamSubnetNewForm', // a unique name for this form
fields: ['type_of_subnet_id', 'subnet_type', 'location', 'security_zone', 'seczone', 'routing_domain', 'zone_confirm', 'subnet_size', 'subnet_confirm', 'iam_addressing_type_id', 'address_space', 'allocation_range', 'new_subnet', 'desc_vr', 'desc_vr_confirm', 'l2env', 'l2env_confirm', 'l3dev', 'l3dev_confirm', 'zone_platform', 'wo', 'iam_network_diagram_id', 'subnet_class', 'project', 'justification', 'project_confirm']
})(IAMSubnetForm);
export default connect(mapStateToProps, mapDispatchToProps)(IAMSubnetFormP);
the select box is rendered as follows
renderTypeOfSubnet() {
let disabled = true;
let data = this.state.data;
console.log(this)
if (Object.keys(this.props.forms.iamSubnetNewForm).length > 0
&& 'values' in this.props.forms.iamSubnetNewForm
&& 'type_of_subnet_id' in this.props.forms.iamSubnetNewForm.values) {
disabled = false;
}
return <Field
label="Please select the type of subnet?"
name="type_of_subnet_id"
component={this.renderSelectField}
type="select" disabled={disabled} data={data}
onBlur={() => {}}
/>;
}
renderSelectField(field) {
const { input, label, type, meta: { touched, error, warning }, data, disabled } = field;
let options = ;
const className = `form-group ${touched && error ? 'has-danger' : ''}`;
const uniqueList = ;
const uniqueListObject = ;
if (input.name == 'type_of_subnet_id') {
this.state.data.map(row => {
if (uniqueList.indexOf(row.subnet_type) === -1) {
uniqueList.push(row.subnet_type);
uniqueListObject.push({ id: row.iam_type_id, text: row.subnet_type, vlan: row.vlan });
}
});
let newuniqueListObject = uniqueListObject.sort(function(a, b) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
options = this.populateOptionsObject(newuniqueListObject);
}
let id = 'select_' + input.name;
if (input.name == 'security_zone' && this.props.forms.iamSubnetNewForm.values.location != '') {
if (this.props.forms.iamSubnetNewForm.values.subnet_type != 'NAT') {
options.unshift(
<option key="" value="">
-- select --
</option>
);
} else {
uniqueListObject.push({ id: 'E1', text: 'N/A' });
options = this.populateOptionsObject(uniqueListObject);
}
} else if (input.name != 'wo' && input.name != 'iam_network_diagram_id' && input.name != 'subnet_class') {
if (this.props.forms.iamSubnetNewForm.values.subnet_type != 'NAT') {
options.unshift(
<option key="" value="">
-- select --
</option>
);
} else if (input.name == 'zone_platform' && this.props.forms.iamSubnetNewForm.values.l3dev_confirm == 'Yes' && this.props.forms.iamSubnetNewForm.values.subnet_type == 'NAT') {
options.unshift(
<option key="N/A" value="N/A">
N/A
</option>
);
} else {
options.unshift(
<option key="" value="">
-- select --
</option>
);
}
} else if (input.name == 'subnet_class' && this.props.forms.iamSubnetNewForm.values.l3dev_confirm == 'Yes' && this.props.forms.iamSubnetNewForm.values.iam_network_diagram_id != '' && this.props.forms.iamSubnetNewForm.values.subnet_type == 'NAT') {
options.unshift(
<option key="N/A" value="N/A">
N/A
</option>
);
}
return (
<div className={className}>
<label className="control-label col-sm-4">{label}</label>
<div className="col-sm-8">
<select
{...input}
onBlur={() => {}}
className="form-control form-control-inline"
type={type}
onChange={event => {
this.resetValues(event);
if (event.target.name == 'type_of_subnet_id') {
if (event.target.value.length > 0) {
let type_of_subnet = _.find(uniqueListObject, { id: event.target.value });
if (type_of_subnet.text == 'NAT') {
this.props.change('security_zone', 'N/A');
this.props.change('seczone', 'E1');
}
this.props.change('subnet_type', type_of_subnet.text);
this.props.change('vlan', type_of_subnet.vlan);
} else {
this.props.change('subnet_type', '');
this.props.change('seczone', '');
this.props.change('security_zone', '');
}
}
this.props.change(event.target.name, event.target.value);
}}
disabled={disabled}
>
{options}
</select>
</div>
<div className="row-fluid">
<div className="col-sm-2" />
<div className="col-sm-10">
{touched &&
((error && (
<span className="text-danger">
<i className="fa fa-exclamation-circle" aria-hidden="true" /> {error}
</span>
)) ||
(warning && (
<span className="text-warning">
<i className="fa fa-question-circle" aria-hidden="true" /> {warning}
</span>
)))}
</div>
</div>
</div>
);
}
It seems like after the change event a re-render is not triggered to update the value on the from end. however it holds the correct value in props
I have replicated issue here
https://codesandbox.io/s/24x376j98n
i need to be able to support multiple forms. for example forms in different components but being rendered on the same view
reactjs redux-form
add a comment |
I am using version 7.2.x and i have fixed the bug with onBlur where it resets teh value of the input. Problem i have now is i can see the state changes and it holds the correct value now but on the gui it does not change the value to show the correct one.
In my reducer i have forms: formReducer,
.
in my component class
const mapStateToProps = state => {
return state;
}
function mapDispatchToProps(dispatch) {
return bindActionCreators(
{
change,
},
dispatch
);
}
const IAMSubnetFormP = reduxForm({
form: 'iamSubnetNewForm', // a unique name for this form
fields: ['type_of_subnet_id', 'subnet_type', 'location', 'security_zone', 'seczone', 'routing_domain', 'zone_confirm', 'subnet_size', 'subnet_confirm', 'iam_addressing_type_id', 'address_space', 'allocation_range', 'new_subnet', 'desc_vr', 'desc_vr_confirm', 'l2env', 'l2env_confirm', 'l3dev', 'l3dev_confirm', 'zone_platform', 'wo', 'iam_network_diagram_id', 'subnet_class', 'project', 'justification', 'project_confirm']
})(IAMSubnetForm);
export default connect(mapStateToProps, mapDispatchToProps)(IAMSubnetFormP);
the select box is rendered as follows
renderTypeOfSubnet() {
let disabled = true;
let data = this.state.data;
console.log(this)
if (Object.keys(this.props.forms.iamSubnetNewForm).length > 0
&& 'values' in this.props.forms.iamSubnetNewForm
&& 'type_of_subnet_id' in this.props.forms.iamSubnetNewForm.values) {
disabled = false;
}
return <Field
label="Please select the type of subnet?"
name="type_of_subnet_id"
component={this.renderSelectField}
type="select" disabled={disabled} data={data}
onBlur={() => {}}
/>;
}
renderSelectField(field) {
const { input, label, type, meta: { touched, error, warning }, data, disabled } = field;
let options = ;
const className = `form-group ${touched && error ? 'has-danger' : ''}`;
const uniqueList = ;
const uniqueListObject = ;
if (input.name == 'type_of_subnet_id') {
this.state.data.map(row => {
if (uniqueList.indexOf(row.subnet_type) === -1) {
uniqueList.push(row.subnet_type);
uniqueListObject.push({ id: row.iam_type_id, text: row.subnet_type, vlan: row.vlan });
}
});
let newuniqueListObject = uniqueListObject.sort(function(a, b) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
options = this.populateOptionsObject(newuniqueListObject);
}
let id = 'select_' + input.name;
if (input.name == 'security_zone' && this.props.forms.iamSubnetNewForm.values.location != '') {
if (this.props.forms.iamSubnetNewForm.values.subnet_type != 'NAT') {
options.unshift(
<option key="" value="">
-- select --
</option>
);
} else {
uniqueListObject.push({ id: 'E1', text: 'N/A' });
options = this.populateOptionsObject(uniqueListObject);
}
} else if (input.name != 'wo' && input.name != 'iam_network_diagram_id' && input.name != 'subnet_class') {
if (this.props.forms.iamSubnetNewForm.values.subnet_type != 'NAT') {
options.unshift(
<option key="" value="">
-- select --
</option>
);
} else if (input.name == 'zone_platform' && this.props.forms.iamSubnetNewForm.values.l3dev_confirm == 'Yes' && this.props.forms.iamSubnetNewForm.values.subnet_type == 'NAT') {
options.unshift(
<option key="N/A" value="N/A">
N/A
</option>
);
} else {
options.unshift(
<option key="" value="">
-- select --
</option>
);
}
} else if (input.name == 'subnet_class' && this.props.forms.iamSubnetNewForm.values.l3dev_confirm == 'Yes' && this.props.forms.iamSubnetNewForm.values.iam_network_diagram_id != '' && this.props.forms.iamSubnetNewForm.values.subnet_type == 'NAT') {
options.unshift(
<option key="N/A" value="N/A">
N/A
</option>
);
}
return (
<div className={className}>
<label className="control-label col-sm-4">{label}</label>
<div className="col-sm-8">
<select
{...input}
onBlur={() => {}}
className="form-control form-control-inline"
type={type}
onChange={event => {
this.resetValues(event);
if (event.target.name == 'type_of_subnet_id') {
if (event.target.value.length > 0) {
let type_of_subnet = _.find(uniqueListObject, { id: event.target.value });
if (type_of_subnet.text == 'NAT') {
this.props.change('security_zone', 'N/A');
this.props.change('seczone', 'E1');
}
this.props.change('subnet_type', type_of_subnet.text);
this.props.change('vlan', type_of_subnet.vlan);
} else {
this.props.change('subnet_type', '');
this.props.change('seczone', '');
this.props.change('security_zone', '');
}
}
this.props.change(event.target.name, event.target.value);
}}
disabled={disabled}
>
{options}
</select>
</div>
<div className="row-fluid">
<div className="col-sm-2" />
<div className="col-sm-10">
{touched &&
((error && (
<span className="text-danger">
<i className="fa fa-exclamation-circle" aria-hidden="true" /> {error}
</span>
)) ||
(warning && (
<span className="text-warning">
<i className="fa fa-question-circle" aria-hidden="true" /> {warning}
</span>
)))}
</div>
</div>
</div>
);
}
It seems like after the change event a re-render is not triggered to update the value on the from end. however it holds the correct value in props
I have replicated issue here
https://codesandbox.io/s/24x376j98n
i need to be able to support multiple forms. for example forms in different components but being rendered on the same view
reactjs redux-form
I am using version 7.2.x and i have fixed the bug with onBlur where it resets teh value of the input. Problem i have now is i can see the state changes and it holds the correct value now but on the gui it does not change the value to show the correct one.
In my reducer i have forms: formReducer,
.
in my component class
const mapStateToProps = state => {
return state;
}
function mapDispatchToProps(dispatch) {
return bindActionCreators(
{
change,
},
dispatch
);
}
const IAMSubnetFormP = reduxForm({
form: 'iamSubnetNewForm', // a unique name for this form
fields: ['type_of_subnet_id', 'subnet_type', 'location', 'security_zone', 'seczone', 'routing_domain', 'zone_confirm', 'subnet_size', 'subnet_confirm', 'iam_addressing_type_id', 'address_space', 'allocation_range', 'new_subnet', 'desc_vr', 'desc_vr_confirm', 'l2env', 'l2env_confirm', 'l3dev', 'l3dev_confirm', 'zone_platform', 'wo', 'iam_network_diagram_id', 'subnet_class', 'project', 'justification', 'project_confirm']
})(IAMSubnetForm);
export default connect(mapStateToProps, mapDispatchToProps)(IAMSubnetFormP);
the select box is rendered as follows
renderTypeOfSubnet() {
let disabled = true;
let data = this.state.data;
console.log(this)
if (Object.keys(this.props.forms.iamSubnetNewForm).length > 0
&& 'values' in this.props.forms.iamSubnetNewForm
&& 'type_of_subnet_id' in this.props.forms.iamSubnetNewForm.values) {
disabled = false;
}
return <Field
label="Please select the type of subnet?"
name="type_of_subnet_id"
component={this.renderSelectField}
type="select" disabled={disabled} data={data}
onBlur={() => {}}
/>;
}
renderSelectField(field) {
const { input, label, type, meta: { touched, error, warning }, data, disabled } = field;
let options = ;
const className = `form-group ${touched && error ? 'has-danger' : ''}`;
const uniqueList = ;
const uniqueListObject = ;
if (input.name == 'type_of_subnet_id') {
this.state.data.map(row => {
if (uniqueList.indexOf(row.subnet_type) === -1) {
uniqueList.push(row.subnet_type);
uniqueListObject.push({ id: row.iam_type_id, text: row.subnet_type, vlan: row.vlan });
}
});
let newuniqueListObject = uniqueListObject.sort(function(a, b) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
options = this.populateOptionsObject(newuniqueListObject);
}
let id = 'select_' + input.name;
if (input.name == 'security_zone' && this.props.forms.iamSubnetNewForm.values.location != '') {
if (this.props.forms.iamSubnetNewForm.values.subnet_type != 'NAT') {
options.unshift(
<option key="" value="">
-- select --
</option>
);
} else {
uniqueListObject.push({ id: 'E1', text: 'N/A' });
options = this.populateOptionsObject(uniqueListObject);
}
} else if (input.name != 'wo' && input.name != 'iam_network_diagram_id' && input.name != 'subnet_class') {
if (this.props.forms.iamSubnetNewForm.values.subnet_type != 'NAT') {
options.unshift(
<option key="" value="">
-- select --
</option>
);
} else if (input.name == 'zone_platform' && this.props.forms.iamSubnetNewForm.values.l3dev_confirm == 'Yes' && this.props.forms.iamSubnetNewForm.values.subnet_type == 'NAT') {
options.unshift(
<option key="N/A" value="N/A">
N/A
</option>
);
} else {
options.unshift(
<option key="" value="">
-- select --
</option>
);
}
} else if (input.name == 'subnet_class' && this.props.forms.iamSubnetNewForm.values.l3dev_confirm == 'Yes' && this.props.forms.iamSubnetNewForm.values.iam_network_diagram_id != '' && this.props.forms.iamSubnetNewForm.values.subnet_type == 'NAT') {
options.unshift(
<option key="N/A" value="N/A">
N/A
</option>
);
}
return (
<div className={className}>
<label className="control-label col-sm-4">{label}</label>
<div className="col-sm-8">
<select
{...input}
onBlur={() => {}}
className="form-control form-control-inline"
type={type}
onChange={event => {
this.resetValues(event);
if (event.target.name == 'type_of_subnet_id') {
if (event.target.value.length > 0) {
let type_of_subnet = _.find(uniqueListObject, { id: event.target.value });
if (type_of_subnet.text == 'NAT') {
this.props.change('security_zone', 'N/A');
this.props.change('seczone', 'E1');
}
this.props.change('subnet_type', type_of_subnet.text);
this.props.change('vlan', type_of_subnet.vlan);
} else {
this.props.change('subnet_type', '');
this.props.change('seczone', '');
this.props.change('security_zone', '');
}
}
this.props.change(event.target.name, event.target.value);
}}
disabled={disabled}
>
{options}
</select>
</div>
<div className="row-fluid">
<div className="col-sm-2" />
<div className="col-sm-10">
{touched &&
((error && (
<span className="text-danger">
<i className="fa fa-exclamation-circle" aria-hidden="true" /> {error}
</span>
)) ||
(warning && (
<span className="text-warning">
<i className="fa fa-question-circle" aria-hidden="true" /> {warning}
</span>
)))}
</div>
</div>
</div>
);
}
It seems like after the change event a re-render is not triggered to update the value on the from end. however it holds the correct value in props
I have replicated issue here
https://codesandbox.io/s/24x376j98n
i need to be able to support multiple forms. for example forms in different components but being rendered on the same view
reactjs redux-form
reactjs redux-form
edited Nov 21 '18 at 17:02
shorif2000
asked Nov 21 '18 at 15:19
shorif2000shorif2000
81363581
81363581
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You should pass value prop to "select" tag
<select
...
value={event.target.value}
...
/>
</select>
Check this return statement
return (
<div className={className}>
<label className="control-label col-sm-4">{label}</label>
<div className="col-sm-8">
<select
{...input}
onBlur={() => {
console.log(field);
console.log(input.value);
}}
className="form-control form-control-inline"
type={type}
value={event.target.value}
onChange={event => {
this.resetValues(event);
if (event.target.name == "type_of_subnet_id") {
if (event.target.value.length > 0) {
let type_of_subnet = _.find(uniqueListObject, {
id: event.target.value
});
if (type_of_subnet.text == "NAT") {
this.props.change("security_zone", "N/A");
this.props.change("seczone", "E1");
}
this.props.change("subnet_type", type_of_subnet.text);
this.props.change("vlan", type_of_subnet.vlan);
} else {
this.props.change("subnet_type", "");
this.props.change("seczone", "");
this.props.change("security_zone", "");
}
} else if (
event.target.name == "routing_domain" &&
this.props.forms.iamSubnetNewForm.values.subnet_type == "NAT" &&
this.props.forms.iamSubnetNewForm.values.seczone == "E1"
) {
this.props.change("zone_confirm", "Yes");
} else if (
event.target.name == "security_zone" &&
this.props.forms.iamSubnetNewForm.values.subnet_type != "NAT" &&
event.target.value.length > 0
) {
let type_of_subnet = _.find(uniqueListObject, {
id: event.target.value
});
this.props.change("seczone", type_of_subnet.seczone);
} else if (event.target.name == "subnet_size") {
if (event.target.value != "") {
this.props.change(
"iam_addressing_type_id",
data[0].iam_addressing_type_id
);
let self = this;
this.props
.requestSubnet(
data[0].iam_addressing_type_id,
this.props.forms.iamSubnetNewForm.values.location,
event.target.value,
this.props.forms.iamSubnetNewForm.values
.type_of_subnet_id,
this.props.forms.iamSubnetNewForm.values.security_zone,
this.props.forms.iamSubnetNewForm.values.routing_domain
)
.then(response => {
let data = response.payload.data;
if (data.header.error) {
if (
data.header.message ==
"Unable to assign a new subnet. The IP Administrator has been notified."
) {
self.setState({
request_subnet: data.header.message
});
} else {
self.handleShowError({
show: true,
errorMsg: data.header.message
});
}
} else {
this.props.change(
"address_space",
data.body.recordset.record.address_space
);
this.props.change(
"allocation_range",
data.body.recordset.record.allocation_range
);
this.props.change(
"new_subnet",
data.body.recordset.record.new_subnet
);
self.setState({ request_subnet: "" });
}
});
} else {
this.props.change(
"iam_addressing_type_id",
data[0].iam_addressing_type_id
);
}
} else if (event.target.name == "zone_platform") {
if (
this.props.forms.iamSubnetNewForm.values.subnet_type !=
"NAT" &&
(this.props.forms.iamSubnetNewForm.values.l3dev_confirm !=
"" &&
this.props.forms.iamSubnetNewForm.values.l3dev_confirm !=
"No")
) {
this.props.fetchIAMInc().then(response => {
let data = response.payload.data.body.recordset.record;
data.map(row => {
if (uniqueList.indexOf(row.remedy_inc) === -1) {
uniqueList.push(row.remedy_inc);
uniqueListObject.push({
id: row.remedy_inc,
text: row.remedy_inc
});
}
});
let newuniqueListObject = uniqueListObject.sort(function (
a,
b
) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
let options = this.populateOptionsObject(
newuniqueListObject
);
options.unshift(
<option key="" value="">
-- select --
</option>
);
this.setState({ wo: options });
});
}
} else if (event.target.name == "wo") {
if (
this.props.forms.iamSubnetNewForm.values.subnet_type !=
"NAT" &&
event.target.value != ""
) {
this.props
.fetchNetworkTopology(event.target.value)
.then(response => {
let data = response.payload.data.body.recordset.record;
data.map(row => {
if (uniqueList.indexOf(row.id) === -1) {
uniqueList.push(row.id);
const text = `${row.remedy_inc} v${row.version}`;
uniqueListObject.push({ id: row.id, text: text });
}
});
let newuniqueListObject = uniqueListObject.sort(function (
a,
b
) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
let options = this.populateOptionsObject(
newuniqueListObject
);
options.unshift(
<option key="" value="">
-- select --
</option>
);
this.setState({ networkTopology: options });
});
} else if (
this.props.forms.iamSubnetNewForm.values.subnet_type ==
"NAT" &&
(this.props.forms.iamSubnetNewForm.values.l2env_confirm !=
"" &&
this.props.forms.iamSubnetNewForm.values.l2env_confirm !=
"No")
) {
this.props
.fetchNetworkTopology(event.target.value)
.then(response => {
let data = response.payload.data.body.recordset.record;
data.map(row => {
if (uniqueList.indexOf(row.id) === -1) {
uniqueList.push(row.id);
const text = `${row.remedy_inc} v${row.version}`;
uniqueListObject.push({ id: row.id, text: text });
}
});
let newuniqueListObject = uniqueListObject.sort(function (
a,
b
) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
let options = this.populateOptionsObject(
newuniqueListObject
);
options.unshift(
<option key="" value="">
-- select --
</option>
);
this.setState({ networkTopology: options });
});
}
} else if (event.target.name == "iam_network_diagram_id") {
if (
this.props.forms.iamSubnetNewForm.values.subnet_type !=
"NAT" &&
event.target.value != ""
) {
this.props.fetchSubnetClass().then(response => {
let data = response.payload.data.body.recordset.record;
data.map(row => {
if (uniqueList.indexOf(row.descriptor) === -1) {
uniqueList.push(row.descriptor);
const text = `${row.name}`;
uniqueListObject.push({
id: row.descriptor,
text: text
});
}
});
let newuniqueListObject = uniqueListObject.sort(function (
a,
b
) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
let options = this.populateOptionsObject(
newuniqueListObject
);
options.unshift(
<option key="" value="">
-- select --
</option>
);
this.setState({ subnetClass: options });
});
} else if (
this.props.forms.iamSubnetNewForm.values.subnet_type ==
"NAT" &&
event.target.value != ""
) {
let data = _.filter(this.state.data, {
iam_type_id: this.props.forms.iamSubnetNewForm.values
.type_of_subnet_id
});
data = _.filter(data, {
loczone: this.props.forms.iamSubnetNewForm.values.location
});
data = _.filter(data, {
seczone: this.props.forms.iamSubnetNewForm.values.seczone
});
data = _.filter(data, {
netzone: this.props.forms.iamSubnetNewForm.values
.routing_domain
});
let found = _.find(data, {
subnet_size: this.props.forms.iamSubnetNewForm.values
.subnet_size
});
if (found === undefined) {
} else {
this.props.change("subnet_class", "N/A");
this.props.change("project", "N/A");
this.props.change("justification", "N/A");
this.props.change("project_confirm", "Yes");
this.setState({ buttonDisabled: false });
}
}
} else if (event.target.name == "subnet_class") {
if (
this.props.forms.iamSubnetNewForm.values.subnet_type !=
"NAT" &&
event.target.value != ""
) {
let data = _.filter(this.state.data, {
iam_type_id: this.props.forms.iamSubnetNewForm.values
.type_of_subnet_id
});
data = _.filter(data, {
loczone: this.props.forms.iamSubnetNewForm.values.location
});
data = _.filter(data, {
seczone: this.props.forms.iamSubnetNewForm.values.seczone
});
data = _.filter(data, {
netzone: this.props.forms.iamSubnetNewForm.values
.routing_domain
});
let found = _.find(data, {
subnet_size: this.props.forms.iamSubnetNewForm.values
.subnet_size
});
if (event.target.value == "Shared" && found !== undefined) {
this.props.change("project", "N/A");
this.props.change("justification", "N/A");
this.props.change("project_confirm", "Yes");
this.setState({ buttonDisabled: false });
} else if (
event.target.value != "Shared" ||
found == undefined
) {
this.setState({ buttonDisabled: true });
}
}
}
this.props.change(event.target.name, event.target.value);
input.onChange(event);
this.setState(prevState => ({
rerender: !prevState.rerender
}));
console.log("need to rerender");
}}
disabled={disabled}
>
{options}
</select>
</div>
<div className="row-fluid">
<div className="col-sm-2" />
<div className="col-sm-10">
{touched &&
((error && (
<span className="text-danger">
<i className="fa fa-exclamation-circle" aria-hidden="true" />{" "}
{error}
</span>
)) ||
(warning && (
<span className="text-warning">
<i className="fa fa-question-circle" aria-hidden="true" />{" "}
{warning}
</span>
)))}
</div>
</div>
</div>
);
this doesn't work
– shorif2000
Nov 22 '18 at 14:09
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415211%2fredux-form-not-updating-select-field%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You should pass value prop to "select" tag
<select
...
value={event.target.value}
...
/>
</select>
Check this return statement
return (
<div className={className}>
<label className="control-label col-sm-4">{label}</label>
<div className="col-sm-8">
<select
{...input}
onBlur={() => {
console.log(field);
console.log(input.value);
}}
className="form-control form-control-inline"
type={type}
value={event.target.value}
onChange={event => {
this.resetValues(event);
if (event.target.name == "type_of_subnet_id") {
if (event.target.value.length > 0) {
let type_of_subnet = _.find(uniqueListObject, {
id: event.target.value
});
if (type_of_subnet.text == "NAT") {
this.props.change("security_zone", "N/A");
this.props.change("seczone", "E1");
}
this.props.change("subnet_type", type_of_subnet.text);
this.props.change("vlan", type_of_subnet.vlan);
} else {
this.props.change("subnet_type", "");
this.props.change("seczone", "");
this.props.change("security_zone", "");
}
} else if (
event.target.name == "routing_domain" &&
this.props.forms.iamSubnetNewForm.values.subnet_type == "NAT" &&
this.props.forms.iamSubnetNewForm.values.seczone == "E1"
) {
this.props.change("zone_confirm", "Yes");
} else if (
event.target.name == "security_zone" &&
this.props.forms.iamSubnetNewForm.values.subnet_type != "NAT" &&
event.target.value.length > 0
) {
let type_of_subnet = _.find(uniqueListObject, {
id: event.target.value
});
this.props.change("seczone", type_of_subnet.seczone);
} else if (event.target.name == "subnet_size") {
if (event.target.value != "") {
this.props.change(
"iam_addressing_type_id",
data[0].iam_addressing_type_id
);
let self = this;
this.props
.requestSubnet(
data[0].iam_addressing_type_id,
this.props.forms.iamSubnetNewForm.values.location,
event.target.value,
this.props.forms.iamSubnetNewForm.values
.type_of_subnet_id,
this.props.forms.iamSubnetNewForm.values.security_zone,
this.props.forms.iamSubnetNewForm.values.routing_domain
)
.then(response => {
let data = response.payload.data;
if (data.header.error) {
if (
data.header.message ==
"Unable to assign a new subnet. The IP Administrator has been notified."
) {
self.setState({
request_subnet: data.header.message
});
} else {
self.handleShowError({
show: true,
errorMsg: data.header.message
});
}
} else {
this.props.change(
"address_space",
data.body.recordset.record.address_space
);
this.props.change(
"allocation_range",
data.body.recordset.record.allocation_range
);
this.props.change(
"new_subnet",
data.body.recordset.record.new_subnet
);
self.setState({ request_subnet: "" });
}
});
} else {
this.props.change(
"iam_addressing_type_id",
data[0].iam_addressing_type_id
);
}
} else if (event.target.name == "zone_platform") {
if (
this.props.forms.iamSubnetNewForm.values.subnet_type !=
"NAT" &&
(this.props.forms.iamSubnetNewForm.values.l3dev_confirm !=
"" &&
this.props.forms.iamSubnetNewForm.values.l3dev_confirm !=
"No")
) {
this.props.fetchIAMInc().then(response => {
let data = response.payload.data.body.recordset.record;
data.map(row => {
if (uniqueList.indexOf(row.remedy_inc) === -1) {
uniqueList.push(row.remedy_inc);
uniqueListObject.push({
id: row.remedy_inc,
text: row.remedy_inc
});
}
});
let newuniqueListObject = uniqueListObject.sort(function (
a,
b
) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
let options = this.populateOptionsObject(
newuniqueListObject
);
options.unshift(
<option key="" value="">
-- select --
</option>
);
this.setState({ wo: options });
});
}
} else if (event.target.name == "wo") {
if (
this.props.forms.iamSubnetNewForm.values.subnet_type !=
"NAT" &&
event.target.value != ""
) {
this.props
.fetchNetworkTopology(event.target.value)
.then(response => {
let data = response.payload.data.body.recordset.record;
data.map(row => {
if (uniqueList.indexOf(row.id) === -1) {
uniqueList.push(row.id);
const text = `${row.remedy_inc} v${row.version}`;
uniqueListObject.push({ id: row.id, text: text });
}
});
let newuniqueListObject = uniqueListObject.sort(function (
a,
b
) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
let options = this.populateOptionsObject(
newuniqueListObject
);
options.unshift(
<option key="" value="">
-- select --
</option>
);
this.setState({ networkTopology: options });
});
} else if (
this.props.forms.iamSubnetNewForm.values.subnet_type ==
"NAT" &&
(this.props.forms.iamSubnetNewForm.values.l2env_confirm !=
"" &&
this.props.forms.iamSubnetNewForm.values.l2env_confirm !=
"No")
) {
this.props
.fetchNetworkTopology(event.target.value)
.then(response => {
let data = response.payload.data.body.recordset.record;
data.map(row => {
if (uniqueList.indexOf(row.id) === -1) {
uniqueList.push(row.id);
const text = `${row.remedy_inc} v${row.version}`;
uniqueListObject.push({ id: row.id, text: text });
}
});
let newuniqueListObject = uniqueListObject.sort(function (
a,
b
) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
let options = this.populateOptionsObject(
newuniqueListObject
);
options.unshift(
<option key="" value="">
-- select --
</option>
);
this.setState({ networkTopology: options });
});
}
} else if (event.target.name == "iam_network_diagram_id") {
if (
this.props.forms.iamSubnetNewForm.values.subnet_type !=
"NAT" &&
event.target.value != ""
) {
this.props.fetchSubnetClass().then(response => {
let data = response.payload.data.body.recordset.record;
data.map(row => {
if (uniqueList.indexOf(row.descriptor) === -1) {
uniqueList.push(row.descriptor);
const text = `${row.name}`;
uniqueListObject.push({
id: row.descriptor,
text: text
});
}
});
let newuniqueListObject = uniqueListObject.sort(function (
a,
b
) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
let options = this.populateOptionsObject(
newuniqueListObject
);
options.unshift(
<option key="" value="">
-- select --
</option>
);
this.setState({ subnetClass: options });
});
} else if (
this.props.forms.iamSubnetNewForm.values.subnet_type ==
"NAT" &&
event.target.value != ""
) {
let data = _.filter(this.state.data, {
iam_type_id: this.props.forms.iamSubnetNewForm.values
.type_of_subnet_id
});
data = _.filter(data, {
loczone: this.props.forms.iamSubnetNewForm.values.location
});
data = _.filter(data, {
seczone: this.props.forms.iamSubnetNewForm.values.seczone
});
data = _.filter(data, {
netzone: this.props.forms.iamSubnetNewForm.values
.routing_domain
});
let found = _.find(data, {
subnet_size: this.props.forms.iamSubnetNewForm.values
.subnet_size
});
if (found === undefined) {
} else {
this.props.change("subnet_class", "N/A");
this.props.change("project", "N/A");
this.props.change("justification", "N/A");
this.props.change("project_confirm", "Yes");
this.setState({ buttonDisabled: false });
}
}
} else if (event.target.name == "subnet_class") {
if (
this.props.forms.iamSubnetNewForm.values.subnet_type !=
"NAT" &&
event.target.value != ""
) {
let data = _.filter(this.state.data, {
iam_type_id: this.props.forms.iamSubnetNewForm.values
.type_of_subnet_id
});
data = _.filter(data, {
loczone: this.props.forms.iamSubnetNewForm.values.location
});
data = _.filter(data, {
seczone: this.props.forms.iamSubnetNewForm.values.seczone
});
data = _.filter(data, {
netzone: this.props.forms.iamSubnetNewForm.values
.routing_domain
});
let found = _.find(data, {
subnet_size: this.props.forms.iamSubnetNewForm.values
.subnet_size
});
if (event.target.value == "Shared" && found !== undefined) {
this.props.change("project", "N/A");
this.props.change("justification", "N/A");
this.props.change("project_confirm", "Yes");
this.setState({ buttonDisabled: false });
} else if (
event.target.value != "Shared" ||
found == undefined
) {
this.setState({ buttonDisabled: true });
}
}
}
this.props.change(event.target.name, event.target.value);
input.onChange(event);
this.setState(prevState => ({
rerender: !prevState.rerender
}));
console.log("need to rerender");
}}
disabled={disabled}
>
{options}
</select>
</div>
<div className="row-fluid">
<div className="col-sm-2" />
<div className="col-sm-10">
{touched &&
((error && (
<span className="text-danger">
<i className="fa fa-exclamation-circle" aria-hidden="true" />{" "}
{error}
</span>
)) ||
(warning && (
<span className="text-warning">
<i className="fa fa-question-circle" aria-hidden="true" />{" "}
{warning}
</span>
)))}
</div>
</div>
</div>
);
this doesn't work
– shorif2000
Nov 22 '18 at 14:09
add a comment |
You should pass value prop to "select" tag
<select
...
value={event.target.value}
...
/>
</select>
Check this return statement
return (
<div className={className}>
<label className="control-label col-sm-4">{label}</label>
<div className="col-sm-8">
<select
{...input}
onBlur={() => {
console.log(field);
console.log(input.value);
}}
className="form-control form-control-inline"
type={type}
value={event.target.value}
onChange={event => {
this.resetValues(event);
if (event.target.name == "type_of_subnet_id") {
if (event.target.value.length > 0) {
let type_of_subnet = _.find(uniqueListObject, {
id: event.target.value
});
if (type_of_subnet.text == "NAT") {
this.props.change("security_zone", "N/A");
this.props.change("seczone", "E1");
}
this.props.change("subnet_type", type_of_subnet.text);
this.props.change("vlan", type_of_subnet.vlan);
} else {
this.props.change("subnet_type", "");
this.props.change("seczone", "");
this.props.change("security_zone", "");
}
} else if (
event.target.name == "routing_domain" &&
this.props.forms.iamSubnetNewForm.values.subnet_type == "NAT" &&
this.props.forms.iamSubnetNewForm.values.seczone == "E1"
) {
this.props.change("zone_confirm", "Yes");
} else if (
event.target.name == "security_zone" &&
this.props.forms.iamSubnetNewForm.values.subnet_type != "NAT" &&
event.target.value.length > 0
) {
let type_of_subnet = _.find(uniqueListObject, {
id: event.target.value
});
this.props.change("seczone", type_of_subnet.seczone);
} else if (event.target.name == "subnet_size") {
if (event.target.value != "") {
this.props.change(
"iam_addressing_type_id",
data[0].iam_addressing_type_id
);
let self = this;
this.props
.requestSubnet(
data[0].iam_addressing_type_id,
this.props.forms.iamSubnetNewForm.values.location,
event.target.value,
this.props.forms.iamSubnetNewForm.values
.type_of_subnet_id,
this.props.forms.iamSubnetNewForm.values.security_zone,
this.props.forms.iamSubnetNewForm.values.routing_domain
)
.then(response => {
let data = response.payload.data;
if (data.header.error) {
if (
data.header.message ==
"Unable to assign a new subnet. The IP Administrator has been notified."
) {
self.setState({
request_subnet: data.header.message
});
} else {
self.handleShowError({
show: true,
errorMsg: data.header.message
});
}
} else {
this.props.change(
"address_space",
data.body.recordset.record.address_space
);
this.props.change(
"allocation_range",
data.body.recordset.record.allocation_range
);
this.props.change(
"new_subnet",
data.body.recordset.record.new_subnet
);
self.setState({ request_subnet: "" });
}
});
} else {
this.props.change(
"iam_addressing_type_id",
data[0].iam_addressing_type_id
);
}
} else if (event.target.name == "zone_platform") {
if (
this.props.forms.iamSubnetNewForm.values.subnet_type !=
"NAT" &&
(this.props.forms.iamSubnetNewForm.values.l3dev_confirm !=
"" &&
this.props.forms.iamSubnetNewForm.values.l3dev_confirm !=
"No")
) {
this.props.fetchIAMInc().then(response => {
let data = response.payload.data.body.recordset.record;
data.map(row => {
if (uniqueList.indexOf(row.remedy_inc) === -1) {
uniqueList.push(row.remedy_inc);
uniqueListObject.push({
id: row.remedy_inc,
text: row.remedy_inc
});
}
});
let newuniqueListObject = uniqueListObject.sort(function (
a,
b
) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
let options = this.populateOptionsObject(
newuniqueListObject
);
options.unshift(
<option key="" value="">
-- select --
</option>
);
this.setState({ wo: options });
});
}
} else if (event.target.name == "wo") {
if (
this.props.forms.iamSubnetNewForm.values.subnet_type !=
"NAT" &&
event.target.value != ""
) {
this.props
.fetchNetworkTopology(event.target.value)
.then(response => {
let data = response.payload.data.body.recordset.record;
data.map(row => {
if (uniqueList.indexOf(row.id) === -1) {
uniqueList.push(row.id);
const text = `${row.remedy_inc} v${row.version}`;
uniqueListObject.push({ id: row.id, text: text });
}
});
let newuniqueListObject = uniqueListObject.sort(function (
a,
b
) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
let options = this.populateOptionsObject(
newuniqueListObject
);
options.unshift(
<option key="" value="">
-- select --
</option>
);
this.setState({ networkTopology: options });
});
} else if (
this.props.forms.iamSubnetNewForm.values.subnet_type ==
"NAT" &&
(this.props.forms.iamSubnetNewForm.values.l2env_confirm !=
"" &&
this.props.forms.iamSubnetNewForm.values.l2env_confirm !=
"No")
) {
this.props
.fetchNetworkTopology(event.target.value)
.then(response => {
let data = response.payload.data.body.recordset.record;
data.map(row => {
if (uniqueList.indexOf(row.id) === -1) {
uniqueList.push(row.id);
const text = `${row.remedy_inc} v${row.version}`;
uniqueListObject.push({ id: row.id, text: text });
}
});
let newuniqueListObject = uniqueListObject.sort(function (
a,
b
) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
let options = this.populateOptionsObject(
newuniqueListObject
);
options.unshift(
<option key="" value="">
-- select --
</option>
);
this.setState({ networkTopology: options });
});
}
} else if (event.target.name == "iam_network_diagram_id") {
if (
this.props.forms.iamSubnetNewForm.values.subnet_type !=
"NAT" &&
event.target.value != ""
) {
this.props.fetchSubnetClass().then(response => {
let data = response.payload.data.body.recordset.record;
data.map(row => {
if (uniqueList.indexOf(row.descriptor) === -1) {
uniqueList.push(row.descriptor);
const text = `${row.name}`;
uniqueListObject.push({
id: row.descriptor,
text: text
});
}
});
let newuniqueListObject = uniqueListObject.sort(function (
a,
b
) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
let options = this.populateOptionsObject(
newuniqueListObject
);
options.unshift(
<option key="" value="">
-- select --
</option>
);
this.setState({ subnetClass: options });
});
} else if (
this.props.forms.iamSubnetNewForm.values.subnet_type ==
"NAT" &&
event.target.value != ""
) {
let data = _.filter(this.state.data, {
iam_type_id: this.props.forms.iamSubnetNewForm.values
.type_of_subnet_id
});
data = _.filter(data, {
loczone: this.props.forms.iamSubnetNewForm.values.location
});
data = _.filter(data, {
seczone: this.props.forms.iamSubnetNewForm.values.seczone
});
data = _.filter(data, {
netzone: this.props.forms.iamSubnetNewForm.values
.routing_domain
});
let found = _.find(data, {
subnet_size: this.props.forms.iamSubnetNewForm.values
.subnet_size
});
if (found === undefined) {
} else {
this.props.change("subnet_class", "N/A");
this.props.change("project", "N/A");
this.props.change("justification", "N/A");
this.props.change("project_confirm", "Yes");
this.setState({ buttonDisabled: false });
}
}
} else if (event.target.name == "subnet_class") {
if (
this.props.forms.iamSubnetNewForm.values.subnet_type !=
"NAT" &&
event.target.value != ""
) {
let data = _.filter(this.state.data, {
iam_type_id: this.props.forms.iamSubnetNewForm.values
.type_of_subnet_id
});
data = _.filter(data, {
loczone: this.props.forms.iamSubnetNewForm.values.location
});
data = _.filter(data, {
seczone: this.props.forms.iamSubnetNewForm.values.seczone
});
data = _.filter(data, {
netzone: this.props.forms.iamSubnetNewForm.values
.routing_domain
});
let found = _.find(data, {
subnet_size: this.props.forms.iamSubnetNewForm.values
.subnet_size
});
if (event.target.value == "Shared" && found !== undefined) {
this.props.change("project", "N/A");
this.props.change("justification", "N/A");
this.props.change("project_confirm", "Yes");
this.setState({ buttonDisabled: false });
} else if (
event.target.value != "Shared" ||
found == undefined
) {
this.setState({ buttonDisabled: true });
}
}
}
this.props.change(event.target.name, event.target.value);
input.onChange(event);
this.setState(prevState => ({
rerender: !prevState.rerender
}));
console.log("need to rerender");
}}
disabled={disabled}
>
{options}
</select>
</div>
<div className="row-fluid">
<div className="col-sm-2" />
<div className="col-sm-10">
{touched &&
((error && (
<span className="text-danger">
<i className="fa fa-exclamation-circle" aria-hidden="true" />{" "}
{error}
</span>
)) ||
(warning && (
<span className="text-warning">
<i className="fa fa-question-circle" aria-hidden="true" />{" "}
{warning}
</span>
)))}
</div>
</div>
</div>
);
this doesn't work
– shorif2000
Nov 22 '18 at 14:09
add a comment |
You should pass value prop to "select" tag
<select
...
value={event.target.value}
...
/>
</select>
Check this return statement
return (
<div className={className}>
<label className="control-label col-sm-4">{label}</label>
<div className="col-sm-8">
<select
{...input}
onBlur={() => {
console.log(field);
console.log(input.value);
}}
className="form-control form-control-inline"
type={type}
value={event.target.value}
onChange={event => {
this.resetValues(event);
if (event.target.name == "type_of_subnet_id") {
if (event.target.value.length > 0) {
let type_of_subnet = _.find(uniqueListObject, {
id: event.target.value
});
if (type_of_subnet.text == "NAT") {
this.props.change("security_zone", "N/A");
this.props.change("seczone", "E1");
}
this.props.change("subnet_type", type_of_subnet.text);
this.props.change("vlan", type_of_subnet.vlan);
} else {
this.props.change("subnet_type", "");
this.props.change("seczone", "");
this.props.change("security_zone", "");
}
} else if (
event.target.name == "routing_domain" &&
this.props.forms.iamSubnetNewForm.values.subnet_type == "NAT" &&
this.props.forms.iamSubnetNewForm.values.seczone == "E1"
) {
this.props.change("zone_confirm", "Yes");
} else if (
event.target.name == "security_zone" &&
this.props.forms.iamSubnetNewForm.values.subnet_type != "NAT" &&
event.target.value.length > 0
) {
let type_of_subnet = _.find(uniqueListObject, {
id: event.target.value
});
this.props.change("seczone", type_of_subnet.seczone);
} else if (event.target.name == "subnet_size") {
if (event.target.value != "") {
this.props.change(
"iam_addressing_type_id",
data[0].iam_addressing_type_id
);
let self = this;
this.props
.requestSubnet(
data[0].iam_addressing_type_id,
this.props.forms.iamSubnetNewForm.values.location,
event.target.value,
this.props.forms.iamSubnetNewForm.values
.type_of_subnet_id,
this.props.forms.iamSubnetNewForm.values.security_zone,
this.props.forms.iamSubnetNewForm.values.routing_domain
)
.then(response => {
let data = response.payload.data;
if (data.header.error) {
if (
data.header.message ==
"Unable to assign a new subnet. The IP Administrator has been notified."
) {
self.setState({
request_subnet: data.header.message
});
} else {
self.handleShowError({
show: true,
errorMsg: data.header.message
});
}
} else {
this.props.change(
"address_space",
data.body.recordset.record.address_space
);
this.props.change(
"allocation_range",
data.body.recordset.record.allocation_range
);
this.props.change(
"new_subnet",
data.body.recordset.record.new_subnet
);
self.setState({ request_subnet: "" });
}
});
} else {
this.props.change(
"iam_addressing_type_id",
data[0].iam_addressing_type_id
);
}
} else if (event.target.name == "zone_platform") {
if (
this.props.forms.iamSubnetNewForm.values.subnet_type !=
"NAT" &&
(this.props.forms.iamSubnetNewForm.values.l3dev_confirm !=
"" &&
this.props.forms.iamSubnetNewForm.values.l3dev_confirm !=
"No")
) {
this.props.fetchIAMInc().then(response => {
let data = response.payload.data.body.recordset.record;
data.map(row => {
if (uniqueList.indexOf(row.remedy_inc) === -1) {
uniqueList.push(row.remedy_inc);
uniqueListObject.push({
id: row.remedy_inc,
text: row.remedy_inc
});
}
});
let newuniqueListObject = uniqueListObject.sort(function (
a,
b
) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
let options = this.populateOptionsObject(
newuniqueListObject
);
options.unshift(
<option key="" value="">
-- select --
</option>
);
this.setState({ wo: options });
});
}
} else if (event.target.name == "wo") {
if (
this.props.forms.iamSubnetNewForm.values.subnet_type !=
"NAT" &&
event.target.value != ""
) {
this.props
.fetchNetworkTopology(event.target.value)
.then(response => {
let data = response.payload.data.body.recordset.record;
data.map(row => {
if (uniqueList.indexOf(row.id) === -1) {
uniqueList.push(row.id);
const text = `${row.remedy_inc} v${row.version}`;
uniqueListObject.push({ id: row.id, text: text });
}
});
let newuniqueListObject = uniqueListObject.sort(function (
a,
b
) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
let options = this.populateOptionsObject(
newuniqueListObject
);
options.unshift(
<option key="" value="">
-- select --
</option>
);
this.setState({ networkTopology: options });
});
} else if (
this.props.forms.iamSubnetNewForm.values.subnet_type ==
"NAT" &&
(this.props.forms.iamSubnetNewForm.values.l2env_confirm !=
"" &&
this.props.forms.iamSubnetNewForm.values.l2env_confirm !=
"No")
) {
this.props
.fetchNetworkTopology(event.target.value)
.then(response => {
let data = response.payload.data.body.recordset.record;
data.map(row => {
if (uniqueList.indexOf(row.id) === -1) {
uniqueList.push(row.id);
const text = `${row.remedy_inc} v${row.version}`;
uniqueListObject.push({ id: row.id, text: text });
}
});
let newuniqueListObject = uniqueListObject.sort(function (
a,
b
) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
let options = this.populateOptionsObject(
newuniqueListObject
);
options.unshift(
<option key="" value="">
-- select --
</option>
);
this.setState({ networkTopology: options });
});
}
} else if (event.target.name == "iam_network_diagram_id") {
if (
this.props.forms.iamSubnetNewForm.values.subnet_type !=
"NAT" &&
event.target.value != ""
) {
this.props.fetchSubnetClass().then(response => {
let data = response.payload.data.body.recordset.record;
data.map(row => {
if (uniqueList.indexOf(row.descriptor) === -1) {
uniqueList.push(row.descriptor);
const text = `${row.name}`;
uniqueListObject.push({
id: row.descriptor,
text: text
});
}
});
let newuniqueListObject = uniqueListObject.sort(function (
a,
b
) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
let options = this.populateOptionsObject(
newuniqueListObject
);
options.unshift(
<option key="" value="">
-- select --
</option>
);
this.setState({ subnetClass: options });
});
} else if (
this.props.forms.iamSubnetNewForm.values.subnet_type ==
"NAT" &&
event.target.value != ""
) {
let data = _.filter(this.state.data, {
iam_type_id: this.props.forms.iamSubnetNewForm.values
.type_of_subnet_id
});
data = _.filter(data, {
loczone: this.props.forms.iamSubnetNewForm.values.location
});
data = _.filter(data, {
seczone: this.props.forms.iamSubnetNewForm.values.seczone
});
data = _.filter(data, {
netzone: this.props.forms.iamSubnetNewForm.values
.routing_domain
});
let found = _.find(data, {
subnet_size: this.props.forms.iamSubnetNewForm.values
.subnet_size
});
if (found === undefined) {
} else {
this.props.change("subnet_class", "N/A");
this.props.change("project", "N/A");
this.props.change("justification", "N/A");
this.props.change("project_confirm", "Yes");
this.setState({ buttonDisabled: false });
}
}
} else if (event.target.name == "subnet_class") {
if (
this.props.forms.iamSubnetNewForm.values.subnet_type !=
"NAT" &&
event.target.value != ""
) {
let data = _.filter(this.state.data, {
iam_type_id: this.props.forms.iamSubnetNewForm.values
.type_of_subnet_id
});
data = _.filter(data, {
loczone: this.props.forms.iamSubnetNewForm.values.location
});
data = _.filter(data, {
seczone: this.props.forms.iamSubnetNewForm.values.seczone
});
data = _.filter(data, {
netzone: this.props.forms.iamSubnetNewForm.values
.routing_domain
});
let found = _.find(data, {
subnet_size: this.props.forms.iamSubnetNewForm.values
.subnet_size
});
if (event.target.value == "Shared" && found !== undefined) {
this.props.change("project", "N/A");
this.props.change("justification", "N/A");
this.props.change("project_confirm", "Yes");
this.setState({ buttonDisabled: false });
} else if (
event.target.value != "Shared" ||
found == undefined
) {
this.setState({ buttonDisabled: true });
}
}
}
this.props.change(event.target.name, event.target.value);
input.onChange(event);
this.setState(prevState => ({
rerender: !prevState.rerender
}));
console.log("need to rerender");
}}
disabled={disabled}
>
{options}
</select>
</div>
<div className="row-fluid">
<div className="col-sm-2" />
<div className="col-sm-10">
{touched &&
((error && (
<span className="text-danger">
<i className="fa fa-exclamation-circle" aria-hidden="true" />{" "}
{error}
</span>
)) ||
(warning && (
<span className="text-warning">
<i className="fa fa-question-circle" aria-hidden="true" />{" "}
{warning}
</span>
)))}
</div>
</div>
</div>
);
You should pass value prop to "select" tag
<select
...
value={event.target.value}
...
/>
</select>
Check this return statement
return (
<div className={className}>
<label className="control-label col-sm-4">{label}</label>
<div className="col-sm-8">
<select
{...input}
onBlur={() => {
console.log(field);
console.log(input.value);
}}
className="form-control form-control-inline"
type={type}
value={event.target.value}
onChange={event => {
this.resetValues(event);
if (event.target.name == "type_of_subnet_id") {
if (event.target.value.length > 0) {
let type_of_subnet = _.find(uniqueListObject, {
id: event.target.value
});
if (type_of_subnet.text == "NAT") {
this.props.change("security_zone", "N/A");
this.props.change("seczone", "E1");
}
this.props.change("subnet_type", type_of_subnet.text);
this.props.change("vlan", type_of_subnet.vlan);
} else {
this.props.change("subnet_type", "");
this.props.change("seczone", "");
this.props.change("security_zone", "");
}
} else if (
event.target.name == "routing_domain" &&
this.props.forms.iamSubnetNewForm.values.subnet_type == "NAT" &&
this.props.forms.iamSubnetNewForm.values.seczone == "E1"
) {
this.props.change("zone_confirm", "Yes");
} else if (
event.target.name == "security_zone" &&
this.props.forms.iamSubnetNewForm.values.subnet_type != "NAT" &&
event.target.value.length > 0
) {
let type_of_subnet = _.find(uniqueListObject, {
id: event.target.value
});
this.props.change("seczone", type_of_subnet.seczone);
} else if (event.target.name == "subnet_size") {
if (event.target.value != "") {
this.props.change(
"iam_addressing_type_id",
data[0].iam_addressing_type_id
);
let self = this;
this.props
.requestSubnet(
data[0].iam_addressing_type_id,
this.props.forms.iamSubnetNewForm.values.location,
event.target.value,
this.props.forms.iamSubnetNewForm.values
.type_of_subnet_id,
this.props.forms.iamSubnetNewForm.values.security_zone,
this.props.forms.iamSubnetNewForm.values.routing_domain
)
.then(response => {
let data = response.payload.data;
if (data.header.error) {
if (
data.header.message ==
"Unable to assign a new subnet. The IP Administrator has been notified."
) {
self.setState({
request_subnet: data.header.message
});
} else {
self.handleShowError({
show: true,
errorMsg: data.header.message
});
}
} else {
this.props.change(
"address_space",
data.body.recordset.record.address_space
);
this.props.change(
"allocation_range",
data.body.recordset.record.allocation_range
);
this.props.change(
"new_subnet",
data.body.recordset.record.new_subnet
);
self.setState({ request_subnet: "" });
}
});
} else {
this.props.change(
"iam_addressing_type_id",
data[0].iam_addressing_type_id
);
}
} else if (event.target.name == "zone_platform") {
if (
this.props.forms.iamSubnetNewForm.values.subnet_type !=
"NAT" &&
(this.props.forms.iamSubnetNewForm.values.l3dev_confirm !=
"" &&
this.props.forms.iamSubnetNewForm.values.l3dev_confirm !=
"No")
) {
this.props.fetchIAMInc().then(response => {
let data = response.payload.data.body.recordset.record;
data.map(row => {
if (uniqueList.indexOf(row.remedy_inc) === -1) {
uniqueList.push(row.remedy_inc);
uniqueListObject.push({
id: row.remedy_inc,
text: row.remedy_inc
});
}
});
let newuniqueListObject = uniqueListObject.sort(function (
a,
b
) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
let options = this.populateOptionsObject(
newuniqueListObject
);
options.unshift(
<option key="" value="">
-- select --
</option>
);
this.setState({ wo: options });
});
}
} else if (event.target.name == "wo") {
if (
this.props.forms.iamSubnetNewForm.values.subnet_type !=
"NAT" &&
event.target.value != ""
) {
this.props
.fetchNetworkTopology(event.target.value)
.then(response => {
let data = response.payload.data.body.recordset.record;
data.map(row => {
if (uniqueList.indexOf(row.id) === -1) {
uniqueList.push(row.id);
const text = `${row.remedy_inc} v${row.version}`;
uniqueListObject.push({ id: row.id, text: text });
}
});
let newuniqueListObject = uniqueListObject.sort(function (
a,
b
) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
let options = this.populateOptionsObject(
newuniqueListObject
);
options.unshift(
<option key="" value="">
-- select --
</option>
);
this.setState({ networkTopology: options });
});
} else if (
this.props.forms.iamSubnetNewForm.values.subnet_type ==
"NAT" &&
(this.props.forms.iamSubnetNewForm.values.l2env_confirm !=
"" &&
this.props.forms.iamSubnetNewForm.values.l2env_confirm !=
"No")
) {
this.props
.fetchNetworkTopology(event.target.value)
.then(response => {
let data = response.payload.data.body.recordset.record;
data.map(row => {
if (uniqueList.indexOf(row.id) === -1) {
uniqueList.push(row.id);
const text = `${row.remedy_inc} v${row.version}`;
uniqueListObject.push({ id: row.id, text: text });
}
});
let newuniqueListObject = uniqueListObject.sort(function (
a,
b
) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
let options = this.populateOptionsObject(
newuniqueListObject
);
options.unshift(
<option key="" value="">
-- select --
</option>
);
this.setState({ networkTopology: options });
});
}
} else if (event.target.name == "iam_network_diagram_id") {
if (
this.props.forms.iamSubnetNewForm.values.subnet_type !=
"NAT" &&
event.target.value != ""
) {
this.props.fetchSubnetClass().then(response => {
let data = response.payload.data.body.recordset.record;
data.map(row => {
if (uniqueList.indexOf(row.descriptor) === -1) {
uniqueList.push(row.descriptor);
const text = `${row.name}`;
uniqueListObject.push({
id: row.descriptor,
text: text
});
}
});
let newuniqueListObject = uniqueListObject.sort(function (
a,
b
) {
var nameA = a.text.toLowerCase(),
nameB = b.text.toLowerCase();
if (nameA < nameB)
//sort string ascending
return -1;
if (nameA > nameB) return 1;
return 0; //default return value (no sorting)
});
let options = this.populateOptionsObject(
newuniqueListObject
);
options.unshift(
<option key="" value="">
-- select --
</option>
);
this.setState({ subnetClass: options });
});
} else if (
this.props.forms.iamSubnetNewForm.values.subnet_type ==
"NAT" &&
event.target.value != ""
) {
let data = _.filter(this.state.data, {
iam_type_id: this.props.forms.iamSubnetNewForm.values
.type_of_subnet_id
});
data = _.filter(data, {
loczone: this.props.forms.iamSubnetNewForm.values.location
});
data = _.filter(data, {
seczone: this.props.forms.iamSubnetNewForm.values.seczone
});
data = _.filter(data, {
netzone: this.props.forms.iamSubnetNewForm.values
.routing_domain
});
let found = _.find(data, {
subnet_size: this.props.forms.iamSubnetNewForm.values
.subnet_size
});
if (found === undefined) {
} else {
this.props.change("subnet_class", "N/A");
this.props.change("project", "N/A");
this.props.change("justification", "N/A");
this.props.change("project_confirm", "Yes");
this.setState({ buttonDisabled: false });
}
}
} else if (event.target.name == "subnet_class") {
if (
this.props.forms.iamSubnetNewForm.values.subnet_type !=
"NAT" &&
event.target.value != ""
) {
let data = _.filter(this.state.data, {
iam_type_id: this.props.forms.iamSubnetNewForm.values
.type_of_subnet_id
});
data = _.filter(data, {
loczone: this.props.forms.iamSubnetNewForm.values.location
});
data = _.filter(data, {
seczone: this.props.forms.iamSubnetNewForm.values.seczone
});
data = _.filter(data, {
netzone: this.props.forms.iamSubnetNewForm.values
.routing_domain
});
let found = _.find(data, {
subnet_size: this.props.forms.iamSubnetNewForm.values
.subnet_size
});
if (event.target.value == "Shared" && found !== undefined) {
this.props.change("project", "N/A");
this.props.change("justification", "N/A");
this.props.change("project_confirm", "Yes");
this.setState({ buttonDisabled: false });
} else if (
event.target.value != "Shared" ||
found == undefined
) {
this.setState({ buttonDisabled: true });
}
}
}
this.props.change(event.target.name, event.target.value);
input.onChange(event);
this.setState(prevState => ({
rerender: !prevState.rerender
}));
console.log("need to rerender");
}}
disabled={disabled}
>
{options}
</select>
</div>
<div className="row-fluid">
<div className="col-sm-2" />
<div className="col-sm-10">
{touched &&
((error && (
<span className="text-danger">
<i className="fa fa-exclamation-circle" aria-hidden="true" />{" "}
{error}
</span>
)) ||
(warning && (
<span className="text-warning">
<i className="fa fa-question-circle" aria-hidden="true" />{" "}
{warning}
</span>
)))}
</div>
</div>
</div>
);
edited Nov 21 '18 at 18:29
answered Nov 21 '18 at 18:13
jagadeesh kadavakollujagadeesh kadavakollu
1024
1024
this doesn't work
– shorif2000
Nov 22 '18 at 14:09
add a comment |
this doesn't work
– shorif2000
Nov 22 '18 at 14:09
this doesn't work
– shorif2000
Nov 22 '18 at 14:09
this doesn't work
– shorif2000
Nov 22 '18 at 14:09
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415211%2fredux-form-not-updating-select-field%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown