Tangerine-Community / tangy-form

<tangy-form> is a web component for creating multipage forms. Other <tangy-*> input elements are included as well.
GNU General Public License v3.0
15 stars 3 forks source link

Add getValueAsMoment helper function #325

Closed esurface closed 2 years ago

esurface commented 2 years ago

New helper function for validation of inputs across form sections.

The function getValueAsMoment is available in the classes TangyPartialDate and TangyEthiopianDate. The function turns any date value including unkown values into useful momentjs objects, e.g.:

inputs.SOME_DATE.value = "2022-03-22"
var _moment = inputs.SOME_DATE.getValueAsMoment()
_moment.isValid()
> true
_moment.format('DD/MM/YYYY')
> 22/03/2022
// with unknown day
inputs.SOME_DATE.value = "2022-03-99"
var _moment = inputs.SOME_DATE.getValueAsMoment()
_moment.isValid()
> true
_moment.format('MM/YYYY')
> 03/2022

HOWEVER this function is only available if you are inside a tangy-form on-submit or on-change logic, or in the tangy-form-item in which the variable is defined. So this does not currently work:

input.SOME_DATE.getValueAsMoment() < input.OTHER_DATE.getValueAsMoment()

This addition will make it so you can use the following logic to check dates against each other anywhere in a form, e.g.:

getValueAsMoment('SOME_DATE') < getValueAsMoment('OTHER_DATE')
esurface commented 2 years ago

@chrisekelley Let me know when we can discuss

chrisekelley commented 2 years ago

See side issue: https://github.com/Tangerine-Community/tangy-form/issues/341