Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

salar / signup dob state #1100

Merged
merged 7 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DatePicker extends React.PureComponent {
date: this.props.value ? toMoment(this.props.value).format(this.props.display_format) : '',
duration: daysFromTodayTo(this.props.value),
is_datepicker_visible: false,
is_placeholder_visible: this.props.placeholder,
is_placeholder_visible: this.props.placeholder && !this.props.value,
};

componentDidMount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const getLocation = (location_list, value, type) => {
class AddressDetails extends Component {
constructor(props) {
super(props);
this.state = { has_fetched_states_list: false };
this.state = { has_fetched_states_list: false, address_state_to_display: '' };
this.form = React.createRef();
// TODO: Find a better solution for handling no-op instead of using is_mounted flags
this.is_mounted = false;
Expand All @@ -55,7 +55,11 @@ class AddressDetails extends Component {
async componentDidMount() {
this.is_mounted = true;
await this.props.fetchStatesList();
if (this.is_mounted) this.setState({ has_fetched_states_list: true });
if (this.is_mounted)
this.setState({
has_fetched_states_list: true,
address_state_to_display: getLocation(this.props.states_list, this.props.value.address_state, 'text'),
});
this.form.current.getFormikActions().validateForm();
}

Expand Down Expand Up @@ -137,19 +141,27 @@ class AddressDetails extends Component {
<DesktopWrapper>
<Autocomplete
{...field}
{...(this.state
.address_state_to_display && {
value: this.state
.address_state_to_display,
})}
data-lpignore='true'
autoComplete='new-password' // prevent chrome autocomplete
dropdown_offset='3.2rem'
type='text'
label={localize('State/Province')}
list_items={this.props.states_list}
onItemSelection={({ value, text }) =>
onItemSelection={({ value, text }) => {
setFieldValue(
'address_state',
value ? text : '',
true
)
}
);
this.setState({
address_state_to_display: '',
});
}}
/>
</DesktopWrapper>
<MobileWrapper>
Expand Down