diff --git a/client/src/components/CustomDateInput.js b/client/src/components/CustomDateInput.js index 633eecbc81..24c4bc4783 100644 --- a/client/src/components/CustomDateInput.js +++ b/client/src/components/CustomDateInput.js @@ -33,7 +33,8 @@ const CustomDateInput = ({ withTime, value, onChange, - onBlur + onBlur, + canClearSelection }) => { const inputRef = useRef() const rightElement = showIcon && CalendarIcon(inputRef.current) @@ -75,7 +76,7 @@ const CustomDateInput = ({ placeholder={inputFormat} maxDate={maxDate} minDate={moment().subtract(100, "years").startOf("year").toDate()} - canClearSelection={false} + canClearSelection={canClearSelection} showActionsBar closeOnSelection={!withTime} timePickerProps={timePickerProps} @@ -98,14 +99,16 @@ CustomDateInput.propTypes = { PropTypes.instanceOf(Date) ]), onChange: PropTypes.func, - onBlur: PropTypes.func + onBlur: PropTypes.func, + canClearSelection: PropTypes.bool } CustomDateInput.defaultProps = { disabled: false, showIcon: true, maxDate: moment().add(20, "years").endOf("year").toDate(), placement: "auto", - withTime: false + withTime: false, + canClearSelection: false } export default CustomDateInput diff --git a/client/src/models/Person.js b/client/src/models/Person.js index 48962183dd..f2ec5727c7 100644 --- a/client/src/models/Person.js +++ b/client/src/models/Person.js @@ -140,9 +140,7 @@ export default class Person extends Model { if (Person.isPrincipal({ role })) { return schema } else { - schema = schema.required( - `You must provide the ${Settings.fields.person.endOfTourDate}` - ) + // endOfTourDate is not required but if there is, it must be greater than today if (Person.isPendingVerification({ pendingVerification })) { schema = schema.test( "end-of-tour-date", diff --git a/client/src/pages/people/Form.js b/client/src/pages/people/Form.js index 921b6ddadb..8036374ffb 100644 --- a/client/src/pages/people/Form.js +++ b/client/src/pages/people/Form.js @@ -590,7 +590,9 @@ const PersonForm = ({ value={values.endOfTourDate} onChange={value => setFieldValue("endOfTourDate", value)} onBlur={() => setFieldTouched("endOfTourDate")} - widget={} + widget={ + + } > {isAdvisor && endOfTourDateInPast && ( diff --git a/client/tests/webdriver/baseSpecs/createNewPerson.spec.js b/client/tests/webdriver/baseSpecs/createNewPerson.spec.js index cb0389bbc2..f7e6fc5f04 100644 --- a/client/tests/webdriver/baseSpecs/createNewPerson.spec.js +++ b/client/tests/webdriver/baseSpecs/createNewPerson.spec.js @@ -168,7 +168,7 @@ describe("Create new Person form page", () => { ) // Don't logout, next test continues… }) - it("Should not save if endOfTourDate is not filled in", async() => { + it("Should save even if endOfTourDate is not filled in", async() => { // Continue on the same page to prevent "Are you sure you wish to navigate away from the page" warning await ( await CreatePerson.getLastName() @@ -181,12 +181,6 @@ describe("Create new Person form page", () => { await ( await CreatePerson.getEmailAddress() ).setValue(VALID_PERSON_ADVISOR.emailAddress) - await (await CreatePerson.getLastName()).click() - let errorMessage = await browser.$( - "input#emailAddress + div.invalid-feedback" - ) - // element should *not* be visible! - await errorMessage.waitForDisplayed({ timeout: 1000, reverse: true }) await ( await CreatePerson.getRank() ).selectByAttribute( @@ -205,20 +199,13 @@ describe("Create new Person form page", () => { "value", await CreatePerson.getRandomOption(await CreatePerson.getCountry()) ) - // This makes sure the help-block is displayed after form submit await (await CreatePerson.getEndOfTourDate()).setValue("") await (await CreatePerson.getLastName()).click() - errorMessage = await (await CreatePerson.getEndOfTourDate()) - .$("..") - .$("..") - .$("..") - .$("..") - .$("div.invalid-feedback") - await errorMessage.waitForExist() - await errorMessage.waitForDisplayed() - expect(await errorMessage.getText()).to.equal( - "You must provide the End of tour" + const errorMessage = await browser.$( + "input#emailAddress + div.invalid-feedback" ) + // element should *not* be visible! + await errorMessage.waitForDisplayed({ timeout: 1000, reverse: true }) // Don't logout, next test continues… })