Closed garethbowen closed 2 months ago
Thank you @garethbowen ! To expand a little on the above given our use case, we intend to use the Luhn-validated ID number to auto-fill some of the other fields in our form, making the process of registering a person easier for our CHWs. The larger impact is that downstream, it will enable us to link this person to our other healthcare systems, reduce duplicates, and, in so doing, provide better care.
@ChinHairSaintClair Does that mean you need to normalize the data, and not just validate it? I'm thinking about if there are spaces included, and that passes validation, but then it's auto-filled later on with spaces intact?
@garethbowen you have a valid point. That seems to be the case, yes.
If we only used the value downstream, it could be easily addressed. However it's still better to fix the issue at source.
I've read up a little and played around with the translate
xpath function, and it seems something like translate(., ' ', '')
would strip spaces from a string, contrary to my original understanding about such a function being available.
See the below screenshot:
This should suffice. However, do you think we need to rethink what the Luhn XPath method returns?
I think the validation can only return a boolean, right? If so then you could have two xpath functions - one to validate and one to transform (more or less what you have demoed). The other option would be to have an enketo widget which does both but that's much more complex to write and maintain than xpath functions.
@garethbowen thank you for your suggestions. I've added a function that strips white spaces and pushed it to the open PR for your review.
Thank you! I'll review on Monday.
Merged. Thank you!
Is your feature request related to a problem? Please describe.
The Luhn algorithm provides for checkbits to detect typos on the client side, but right now there's no way to run this validation in enketo forms.
Describe the solution you'd like
Include a custom xpath function to validate the given number is valid.