From 6e33fd85573c728806992b457acf151451a6440b Mon Sep 17 00:00:00 2001 From: Ramananda Panda Date: Fri, 24 Aug 2018 16:25:05 +0530 Subject: [PATCH] reseting state on closeDialog --- index.js | 94 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 51 insertions(+), 43 deletions(-) diff --git a/index.js b/index.js index b805e64..6d87150 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,12 @@ class DialogInput extends React.Component{ constructor(props){ super(props); this.state = {inputModal:'',submitDisabled:true} + this.baseState = this.state; + } + closeDialog(){ + this.setState(this.baseState,()=>{ + this.props.closeDialog(); + }) } render(){ let title = this.props.title || ''; @@ -19,6 +25,7 @@ class DialogInput extends React.Component{ var isInputRequired = (textProps && textProps.required )|| false; cancelText = (Platform.OS === 'ios')? cancelText:cancelText.toUpperCase(); submitText = (Platform.OS === 'ios')? submitText:submitText.toUpperCase(); + return( { - this.props.closeDialog(); + this.closeDialog(); }}> - - - - {title} - {this.props.message} - { - if(inputModal.trim()){ - this.setState({inputModal:inputModal,submitDisabled:false}) - }else{ - if(isInputRequired) - this.setState({inputModal:inputModal,submitDisabled:true}) - else - this.setState({inputModal}); - } - }} - /> - - - { - this.props.closeDialog(); - }}> - {cancelText} - - - { - this.props.submitInput(this.state.inputModal); - }}> - {submitText} - + + + + {title} + {this.props.message} + { + let trimmedInput = inputModal.trim(); + if(trimmedInput){ + this.setState({inputModal:trimmedInput,submitDisabled:false}) + }else{ + if(isInputRequired) + this.setState({inputModal:trimmedInput,submitDisabled:true}) + else + this.setState({inputModal}); + } + }} + /> + + + { + this.closeDialog(); + }}> + {cancelText} + + + { + this.props.submitInput(this.state.inputModal); + }}> + {submitText} + + - );