Hi great forum!
Once again I’m hoping you can help.
I’m collecting id numbers such as ST0231 and LW0023. This is done where the initial letters are chosen in a multiple select, and in the next screen the numbers are added. The letters and numbers are then combined with a calculation statement.
When numbers are entered the initial zeros are deleted.
ST is chosen, 0231 is entered but displayed as 231, and the id is saved as ST231.
Is it possible to keep the initial zeroes and still use the numeric keyboard as default?
I can only find forums-post related to ODK 1.
I’ve tried using the HTML attributes pattern="[0-9]*" and tel, but it doesn’t seem to work - or at least i cannot figure out a solution using the attributes.
In your calculate you can append extra zeroes to the number using
padStart. See link below for an example.
Thanks for the answer, It might be a doable solution, i do however have an issue. I’m collection up to 17 different types of id (different initial letters). These do not all contain the same number of digits, it ranges from 4-8. It’s important that the ids are exact and they cannot contain more or less digits.
I’m aware that i could implement your solution, if I make use of if-statements, but I would prefer not to if it’s possible.
You could implement the branching logic without using
ifs but with a map from the prefix to an integer.
Another solution is to set the
inputmode on the
input element. This attribute can force the numeric keyboard to be used even when the
type is text. This feature, however, is only available on devices with recent versions of the WebView. See links below for more information.
You could set the inputAttributes.type for your text prompt to number. This will restrict what the user can enter to numbers and allow you to keep the leading 0’s. I’ve attached indicators.xlsx (10.9 KB)
as an example.
@linl33 Thanks for your suggestions! I’m glad to have learned about
@clarice_larson Your suggestion works perfectly thanks! I’m sure I’ve tried your idea before, but i think i might have run into some problems with my model-sheet.