javascript replace

leblancphil

Member
Hello,
I would like to replace comma, by dot in a decimal element.
I tried a javascript in my element, but no result
var str = "{mytable___mydecimalEelement}";
var res = str.replace(/,/g, ".");
Thanks for your help
 
Placeholders don't work in JavaScript. You'll have to get the element value from the Fabrik element object ...

var str = Fabrik.getBlock('form_X').formElement.get('mytable___mydecimalElement').getValue();
var res = str/replace(/,/g, '.');

replace X in form_X with your numeric form ID.

If you want to set the value in the element to the new value ...

Fabrik.getBlock('form_X').formElement.get('mytable___mydecimalElement').update(res);

-- hugh
 
Thanks,
Should I put it in the javascript textarea of the element or create a js fille ?
Cause I have no result. It's a repeatgroup element, it is a problem with javascript ?
 
Ah, so are you trying to do it as they change the element?

Then ...

this.update(this.getValue().replace(/,/,'.'));

... in the JS box, running on blur (probably, maybe change).

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top