Hello, i have created my own version of the vitals html form. Now since i’m in a french system i would like to represent a decimal with a comma instead of a dot. how can i achieve that.
Thanks.
Hello, i have created my own version of the vitals html form. Now since i’m in a french system i would like to represent a decimal with a comma instead of a dot. how can i achieve that.
Thanks.
@marafa set the lang = “fr-FR” this would set your input to the french system and the comma would replace the dot.
Hi. is the lang the same as the default locale? if that is the case, i changed it already and i have the same issues.
Yes the default locale @marafa Ohhh Which version of HTML are using?
I don’t really know the version of html. I just modify the vitals form that comes with openmrs 2.3.0 and just added new obs to fit my need.
Ohhh okay kindly share with me a copy of your code on pastebin please.
Here it is: <!-- ~ The contents of this file are subject to the OpenMRS Public License - Pastebin.com
This is a dynamic form and may not work well explicitly to change decimal separator based on the locale. by lang
though you can change setting of your machine to french.
suggestion;
tweak your obs variables using toLocaleString()
method e.g for bmi
var bmi = calculateBmi(wt, ht);
var bmiFormatted = bmi.toLocaleString('fr', { minimumFractionDigits: 1, maximumFractionDigits: 1 });
jq('#calculated-bmi').html(bmiFormatted);
jq('#hidden-calculated-bmi').val(bmiFormatted);
note:this uses the French locale (specified as “fr”) and sets the minimum and maximum fraction digits to 1, meaning that only one decimal place is shown.
tempereature
jq(form).find('#temperature').find('.value').text(temperature.toFixed(1).replace(".", ","));
Hi @thembo42. Thanks for the tip. it works but only for display purposes. I want to actually allow the textbox to accept let’s say 37,6 instead of 37.6
Thanks
sorry @marafa for delay, I believe all this has implementation already unless otherwise. But to respond, we could use javascript to replace a dot with a comma on input. forexample;
<input type="text" id="myInput" oninput="formatInputValue()">
<script>
function formatInputValue() {
var input = document.getElementById("myInput");
var value = input.value;
var formattedValue = value.replace(",", ".");
input.value = formattedValue;
}
</script>
this allows for user input with comma,
be sure to tweak to your use-case
Thanks @thembo42 for the reply. Maybe i did not cleary explain what i’m trying to achieve. if i take the example of the temperature, there is a control that is not allowing to record for example 37,5. As soon i leave the textbox there is a message forcing me to put 37.5, that is the behaviour i’m trying to change.
i want to be able to validate the value with the comma.
Maybe i have to do something in the htmlform module itself. Thanks.
Number format, like date format, would ideally respect browser locale setting.
sure!, @marafa whats your browser locale set to?