diff options
| -rw-r--r-- | app/javascript/vehicle_journeys/components/tools/DuplicateVehicleJourney.js | 12 | 
1 files changed, 12 insertions, 0 deletions
| diff --git a/app/javascript/vehicle_journeys/components/tools/DuplicateVehicleJourney.js b/app/javascript/vehicle_journeys/components/tools/DuplicateVehicleJourney.js index 0c1c81114..6cce3eaad 100644 --- a/app/javascript/vehicle_journeys/components/tools/DuplicateVehicleJourney.js +++ b/app/javascript/vehicle_journeys/components/tools/DuplicateVehicleJourney.js @@ -8,6 +8,7 @@ export default class DuplicateVehicleJourney extends Component {      this.state = {}      this.onFormChange = this.onFormChange.bind(this)      this.handleSubmit = this.handleSubmit.bind(this) +    this.disableValidateButton = this.disableValidateButton.bind(this)    }    componentWillReceiveProps() { @@ -58,6 +59,16 @@ export default class DuplicateVehicleJourney extends Component {      return vjas.departure_time[type]    } +  disableValidateButton() { +    /* We disable the button in two cases :  +    - if the additional_time_hh or additional_time_mm are above their input max value +    - if if their is no change in the other inputs to avoid making a coping of the selected VJ  +    */ +    let incorrectDT = isNaN(this.state.duplicate_time_hh) || isNaN(this.state.duplicate_time_mm) || this.state.duplicate_time_hh > 23 || this.state.duplicate_time_mm > 59 +    let noInputChanges = this.state.additional_time == 0 && this.state.originalDT.hour == this.state.duplicate_time_hh && this.state.originalDT.minute == this.state.duplicate_time_mm +    return incorrectDT || noInputChanges +  } +    render() {      if(this.props.status.isFetching == true) {        return false @@ -171,6 +182,7 @@ export default class DuplicateVehicleJourney extends Component {                            className={'btn btn-primary ' + (this.state.additional_time == 0 && this.state.originalDT.hour == this.state.duplicate_time_hh && this.state.originalDT.minute == this.state.duplicate_time_mm ? 'disabled' : '')}                            type='button'                            onClick={this.handleSubmit} +                          disabled={this.disableValidateButton()}                            >                            Valider                          </button> | 
