diff --git a/mixins/WidgetMixin.js b/mixins/WidgetMixin.js index e6d9339..49bb43f 100644 --- a/mixins/WidgetMixin.js +++ b/mixins/WidgetMixin.js @@ -22,6 +22,7 @@ module.exports = { formStyles: PropTypes.object, validationImage: PropTypes.bool, openModal: PropTypes.func, + customValidationView: PropTypes.func, // navigator: , onFocus: PropTypes.func, onBlur: PropTypes.func, @@ -43,6 +44,7 @@ module.exports = { navigator: null, onFocus: () => {}, onBlur: () => {}, + customValidationView: () => {}, validateOnEmpty: false, }; }, @@ -215,11 +217,10 @@ module.exports = { if (hasValue && hasImageProp && !isOptionWidget && shouldShowValidationImage && toValidate) { const imageSrc = hasValidationErrors ? require('../icons/delete_sign.png'):require('../icons/checkmark.png'); - return ( ); @@ -231,7 +232,7 @@ module.exports = { return ( ); @@ -239,4 +240,41 @@ module.exports = { return null; }, + + _renderCustomValidationView() { + var validators = null; + if (this.props.displayValue) { + // in case of modal widget + validators = GiftedFormManager.getValidators(this.props.formName, this.props.displayValue); + } else { + validators = GiftedFormManager.getValidators(this.props.formName, this.props.name); + } + + let toValidate = false; + if (Array.isArray(validators.validate)) { + if (validators.validate.length > 0) { + toValidate = true; + } + } + + // @todo image delete_sign / checkmark should be editable via option + // @todo options enable live validation + + let hasValue = typeof this.state.value !== 'undefined' && this.state.value !== ''; + + if (this.props.validateOnEmpty) { + hasValue = true; + } + + const hasValidationErrors = this.state.validationErrorMessage !== null; + const isOptionWidget = this.props.type === 'OptionWidget'; + const shouldShowValidationImage = this.props.validationImage === true; + + if (this.props.customValidationView) { + const showValidation = hasValue && !isOptionWidget && shouldShowValidationImage && toValidate; + const isValid = !hasValidationErrors; + return this.props.customValidationView(showValidation, isValid) + } + return null; + }, }; diff --git a/widgets/ModalWidget.js b/widgets/ModalWidget.js index 6323f84..53b7632 100644 --- a/widgets/ModalWidget.js +++ b/widgets/ModalWidget.js @@ -54,7 +54,7 @@ module.exports = createReactClass({ return ( ); @@ -114,7 +114,7 @@ module.exports = createReactClass({ marginLeft: 10, tintColor: '#097881', }} - resizeMode={Image.resizeMode.contain} + resizeMode="contain" source={require('../icons/close.png')} /> @@ -139,7 +139,7 @@ module.exports = createReactClass({ marginRight: 10, tintColor: '#097881', }} - resizeMode={Image.resizeMode.contain} + resizeMode="contain" source={require('../icons/check.png')} /> @@ -276,6 +276,8 @@ module.exports = createReactClass({ > {this._renderImage()} + {this._renderCustomValidationView()} + {this.props.title} {this.state.value} diff --git a/widgets/OptionWidget.js b/widgets/OptionWidget.js index 34210ae..2e864ee 100644 --- a/widgets/OptionWidget.js +++ b/widgets/OptionWidget.js @@ -27,7 +27,7 @@ module.exports = createReactClass({ return ( ); @@ -63,6 +63,7 @@ module.exports = createReactClass({ > {this._renderImage()} + {this._renderCustomValidationView()} {this.props.title} diff --git a/widgets/RowWidget.js b/widgets/RowWidget.js index c0a35bb..0a8278d 100644 --- a/widgets/RowWidget.js +++ b/widgets/RowWidget.js @@ -28,7 +28,7 @@ module.exports = createReactClass({ return ( ); diff --git a/widgets/SelectCountryWidget.js b/widgets/SelectCountryWidget.js index 130d8f8..bcddf79 100644 --- a/widgets/SelectCountryWidget.js +++ b/widgets/SelectCountryWidget.js @@ -1857,7 +1857,7 @@ module.exports = createReactClass({ }}> {this._renderImage()} + {this._renderCustomValidationView()} {this.props.title} diff --git a/widgets/TextAreaWidget.js b/widgets/TextAreaWidget.js index 72811e3..39302dd 100644 --- a/widgets/TextAreaWidget.js +++ b/widgets/TextAreaWidget.js @@ -21,6 +21,7 @@ module.exports = createReactClass({ render() { return ( + {this._renderCustomValidationView()} {this._renderImage()} + {this._renderCustomValidationView()} {this.props.title} @@ -78,6 +79,7 @@ module.exports = createReactClass({ {this._renderImage()} + {this._renderCustomValidationView()} {this._renderTitle()}