How can I make it so on the Edit/Copy pages numeric values aren't filled into the textboxes with commas eg. 1,000.00? I just want them to fill as 1000.00.
Edit/Copy pages inserting numbers that are over 1000 with commas
-
- User
- Posts: 9394
If you have enabled the advanced setting Use View Tag format for edit, you may try disable it.
-
- User
- Posts: 171
Combining these two suggestions I came up with:
Client Scripts -> Table-Specific -> Add/Copy Page and Edit Page ->Startup Script
// Remove commas from currency inputs
$("input[name='x_Price']").change(function() {
var $val = $(this).fields("Price").value().toString();
$(this).fields("Price").value($val.replace(/,/g,''));
});
$("input[name='x_Price']").trigger('change');
This removes commas while the page is loaded and it has the added benefit of removing commas from price boxes if a user happens to type one.
But this does not work for detail tables within Client Scripts -> Table-Specific -> List Page ->Startup Script and I am unsure why. Could it be for a similar reason as what was discovered here: viewtopic.php?t=55301
I need it to work in detail tables as well. Further assistance would be appreciated.
-
- User
- Posts: 9394
You better use Client Side Events instead or you should write correct CSS selectors to select the input elements in the detail grid.
-
- User
- Posts: 171
I'm unsure what you mean, what I wrote was a client side event no?
If you mean try putting it under Client Script rather than Startup Script I did and got the same result.
I also tried iterating through all price inputs with
$("input[name*='Price']").change(function() {
$("input[name*='Price']").trigger('each');
}
$("input[name*='Price']").each(function() {
console.log($(this).fields("Price"));
var $val = $(this).fields("Price").value().toString();
$(this).fields("Price").value($val.replace(/,/g,''));
});
$("input[name*='Price']").trigger('change');
But this also results in $(this).fields("Price") returning undefined.
-
- User
- Posts: 9394
arbei wrote:
You better use Client Side Events
You may click the link and read the docs. "Client Side Events" are under Field Setup -> Edit Tag.
-
- User
- Posts: 171
Ah that makes sense thank you. Within Price -> Field Setup -> Edit Tag:
{ // keys = event types, values = handler functions
"change": function(e) {
var $val = $(this).fields("Price").value().toString();
$(this).fields("Price").value($val.replace(/,/g,''));
}
}
Prevents user entry of commas into the price inputs however it does not prevent Edit/Copy pages from inserting commas for numbers over 1000 when initially loading the page.
Is there a way to trigger this event when the page loads like I was able to do with the events in Startup Script? I need Edit/Copy pages to not load the commas into the textboxes.
-
- User
- Posts: 171
This should work somewhere however I don't know where to put it.
$(this).triggerHandler("change");
Putting it outside of the brackets in the previous code within Price -> Field Setup -> Edit Tag results in an error preventing the site from generating. And putting it within Startup Script as:
$("input[id*='Price']").triggerHandler("change");
results in an error about $("input[id*='Price']").value being undefined.
Within Price -> Field Setup -> Edit Tag I also tried changing this line:
"change": function(e) {
to
"change ready": function(e) {
based on the second example in the PHPMaker docs link but it seemed to have no effect.
-
- User
- Posts: 171
Ah based on other jQuery help I found on the internet it seemed like the selector input[id*='Price'] would trigger the change event for any inputs with IDs containing "Price". I don't fully understand why but it seems like this doesn't work like this in this case.
So based on your suggestion of being more specific I came up with:
// Client Scripts -> Table-Specific -> Add/Copy Page and Edit Page ->Startup Script
var count = document.getElementById("key_count_fQuoteDetailsgrid").value;
for (let i = 1; i <= count; i++) {
try {
$("input[id='x" + i + "_Price']").triggerHandler("change");
} catch (e) {
break;
}
}
Which combined with the previous code in Price -> Field Setup -> Edit Tag works great to prevent detail tables from inserting commas on Edit/Copy and also prevent commas from being entered by users.
Problem solved, thanks for guiding me in the right direction.