import React, { Component } from 'react' import { Form, Field } from 'react-final-form' import { Input, NumericTextBox, Switch } from '@progress/kendo-react-inputs' import { DatePicker } from '@progress/kendo-react-dateinputs' import { DropDownList } from '@progress/kendo-react-dropdowns'; import { Button } from '@progress/kendo-react-buttons'; const onSubmit = async values => { window.alert(JSON.stringify(values, 0, 2)) } const formValidation = (values) => { const errors = {}; if (!values.departureCity) { errors.departureCity = "Departure city is Required"; } if (!values.arrivalCity) { errors.arrivalCity = "Аrrival city is Required"; } if (!values.numberOfPassengers) { errors.numberOfPassengers = "Required"; } else if (values.numberOfPassengers > 40) { errors.numberOfPassengers = "The maximun passengers per registration is 40"; } if (!values.departureDate) { errors.departureDate = "Please select a departure date"; } if (!values.arrivalDate) { errors.arrivalDate = "Please select an arrival date"; } let todaysDate = new Date(); todaysDate.setHours(0, 0, 0, 0); let departureDatevalue = new Date(values.departureDate) let arrivalDatevalue = new Date(values.arrivalDate); departureDatevalue.setSeconds(departureDatevalue.getSeconds() + 1); arrivalDatevalue.setSeconds(arrivalDatevalue.getSeconds() + 2); if (departureDatevalue <= todaysDate) { errors.departureDate = "The departure date cannot be in the past"; } else if (departureDatevalue > arrivalDatevalue) { errors.arrivalDate = "The arrival cannot be before departure date"; } return errors; } const initialValues = { departureCity: "", arrivalCity: "", numberOfPassengers: 1, departureDate: new Date(), arrivalDate: new Date(), class: "Economy", directFlight: false }; const kendoHOC = (type, {input, meta, label, ...rest}) => { const Type = type; const LabelElement = type !== DropDownList ? 'label' : 'span'; if (type === NumericTextBox && input.value === '') { input.value = null; } return {label} {meta.error && meta.touched && {meta.error}} ; }; const KendoInput = (options) => (kendoHOC(Input, options)) const KendoNumericTextBox = (options) => (kendoHOC(NumericTextBox, options)) const KendoDatePicker = (options) => (kendoHOC(DatePicker, options)) const KendoDropDown = (options) => (kendoHOC(DropDownList, options)) const KendoSwitch = (options) => (kendoHOC(Switch, options)) class FinalForm extends Component { render() { return (
Flight Search
(
 
)} />
) } } export default FinalForm