Page 1 of 1
Reset, or clear field after save changes
Posted: 2020-04-01 18:01
by dharbitindy
Greetings,
I'm trying to figure out how to reset, or clear a field in the detail view after saving changes. For example; I have a field with a default of 0.00 and I put 2.00 in and use that in a calculated field, but then I need to reset the 2.00 back to 0.00 after saving changes.
Thank you,
David
Re: Reset, or clear field after save changes
Posted: 2020-04-01 18:31
by pbottcher
Hi,
can you explain why you need to do so? This would change your dataset and once you save the changes you will overwrite the data for that field and the calculated field again.
Re: Reset, or clear field after save changes
Posted: 2020-04-01 19:46
by dharbitindy
I have a balance field that I'm updating with 2 other fields, add_used, and add_purch. The math is working to change the balance each time that I save changes even if I put a 0.00 in either of the add fields, but I'd like to zero out the add_used and/or add_purch fields after clicking the Save Changes button. The balance field is a read only calculated field. I could do this I suppose with another table, but it would be nice to make this work if it is doable.
Thanks,
David
Re: Reset, or clear field after save changes
Posted: 2020-04-01 20:33
by pbottcher
Hi,
you could try to to use the TABLENAME-dv.js
and add:
Code: Select all
$j(function {
if($j('[name="SelectedID"]').length) {
$j('#YOURFIELD').val('0');
}
})
Re: Reset, or clear field after save changes
Posted: 2020-04-01 20:49
by dharbitindy
Great! I'll give it a try when I return home from work this evening. Thank you, much appreciated as usual.
David
Re: Reset, or clear field after save changes
Posted: 2020-04-02 01:40
by dharbitindy
Unfortunately that didn't change the add_used field. I may have something wrong here though. mnt_inv_now is the Table and add_used is the field.
$j(function {
if($j('[mnt_inv_now="SelectedID"]').length) {
$j('#add_used').val('0');
}
})
Thanks,
David
Re: Reset, or clear field after save changes
Posted: 2020-04-02 06:15
by pbottcher
Hi,
you changed the selector. So I guess that is the problem.
Try
$j(function {
if($j('[name="SelectedID"]').length) {
$j('#add_used').val('0');
}
})
Re: Reset, or clear field after save changes
Posted: 2020-04-02 13:45
by dharbitindy
My apologies, I should have mentioned that I did try leaving the selector as name before last post, but no luck there either.
Thanks,
David
Re: Reset, or clear field after save changes
Posted: 2020-04-02 15:59
by pbottcher
Hi,
that is strange. On my testsystem it works fine. What type of field is the add_used? Where did you put the code? Maybe you can post that file.
Re: Reset, or clear field after save changes
Posted: 2020-04-02 16:47
by dharbitindy
The add_used and add_purch fields are of Decimal Type with a default value of 0.00
Thanks,
David
Re: Reset, or clear field after save changes
Posted: 2020-04-02 17:07
by pbottcher
Hi,
can you please try once with only the code that I provided (comment all the rest).
Both fields are input fields, correct?
Re: Reset, or clear field after save changes
Posted: 2020-04-02 17:41
by dharbitindy
Okay, commented all other code above, and yes, both are input fields. For some reason, still didn't work on my end. Also cleared browser cache, then deleted existing test records, and created new records just in case the cache was a problem.
Re: Reset, or clear field after save changes
Posted: 2020-04-02 21:52
by dharbitindy
pböttcher's code was of course spot on. The problem was with a file on my end. Thank you for the expertise!
David