Skip to content

InputBase: Add minLength, maxLength, required#1050

Open
olleolleolle wants to merge 7 commits into
masterfrom
feature/minlength
Open

InputBase: Add minLength, maxLength, required#1050
olleolleolle wants to merge 7 commits into
masterfrom
feature/minlength

Conversation

@olleolleolle

@olleolleolle olleolleolle commented Feb 15, 2020

Copy link
Copy Markdown
Contributor

This PR adds validation settings to individual form elements.

Using HTML attributes, we rely on the browser's input validity features.

Example:

                 <TextInput labelMsg="forms.person.firstName" name="first_name"
                    initialValue={ person.first_name }
                    constraints={ { required: true, maxLength: 20, minLength: 5 } } />

How to make a Pane validatable:

  1. add constraints={ { minLength: 5, maxLength: 30, required: true } } to a Form field
  2. add the isValid state to the Form containing the field
  3. add the onValidityChange(newValidity) event handler to the Form. This will PASS ON the change. Example:
        onValidityChange(newValidity) {
         console.log("PersonForm changed", newValidity);
    
         if (this.props.onValidityChange) {
             this.props.onValidityChange(newValidity);
         }
     }
  4. add the onValidityChange(newValidity) event handler to the Pane. This will set the isValid local state. Example:
    onValidityChange(newValidity) {
     console.debug('AddPersonPane onValidityChange', newValidity);
    
      if (newValidity !== this.state.isValid) {
             this.setState({
                 isValid: newValidity
             });
         }
     }
  5. show or hide the Pane Footer switching on the isValid state. Example:
     renderPaneFooter(data) {
         if (!this.state.isValid) {
             return null;
         }
         
         return (
             <Button className="EditPersonTagPane-saveButton"
                 labelMsg="panes.editPersonTag.saveButton"
                 onClick={ this.onSubmit.bind(this) }/>
         );
     }

See #43

@olleolleolle olleolleolle force-pushed the feature/minlength branch 2 times, most recently from 2ef7a4f to 70bfd5b Compare February 15, 2020 15:31
@olleolleolle olleolleolle changed the title InputBase: Add minimumLength, maximumLength, required InputBase: Add minLength, maxLength, required Feb 15, 2020
 - New API: onValidityChange(newValidity)
 - This propagates to given this.props.onValidityChange
 - There is much to do to get this in place everywhere
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant