Reset, or clear field after save changes

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
dharbitindy
Veteran Member
Posts: 101
Joined: 2019-05-26 18:38

Reset, or clear field after save changes

Post by dharbitindy » 2020-04-01 18:01

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

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Reset, or clear field after save changes

Post by pbottcher » 2020-04-01 18:31

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.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

dharbitindy
Veteran Member
Posts: 101
Joined: 2019-05-26 18:38

Re: Reset, or clear field after save changes

Post by dharbitindy » 2020-04-01 19:46

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

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Reset, or clear field after save changes

Post by pbottcher » 2020-04-01 20:33

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');
  }
})

Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

dharbitindy
Veteran Member
Posts: 101
Joined: 2019-05-26 18:38

Re: Reset, or clear field after save changes

Post by dharbitindy » 2020-04-01 20:49

Great! I'll give it a try when I return home from work this evening. Thank you, much appreciated as usual.

David

dharbitindy
Veteran Member
Posts: 101
Joined: 2019-05-26 18:38

Re: Reset, or clear field after save changes

Post by dharbitindy » 2020-04-02 01:40

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

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Reset, or clear field after save changes

Post by pbottcher » 2020-04-02 06:15

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');
}
})
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

dharbitindy
Veteran Member
Posts: 101
Joined: 2019-05-26 18:38

Re: Reset, or clear field after save changes

Post by dharbitindy » 2020-04-02 13:45

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

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Reset, or clear field after save changes

Post by pbottcher » 2020-04-02 15:59

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.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

dharbitindy
Veteran Member
Posts: 101
Joined: 2019-05-26 18:38

Re: Reset, or clear field after save changes

Post by dharbitindy » 2020-04-02 16:47

The add_used and add_purch fields are of Decimal Type with a default value of 0.00

Thanks,
David
Attachments
mnt_inv_now-dv-js.zip
(436 Bytes) Downloaded 93 times

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Reset, or clear field after save changes

Post by pbottcher » 2020-04-02 17:07

Hi,

can you please try once with only the code that I provided (comment all the rest).

Both fields are input fields, correct?
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

dharbitindy
Veteran Member
Posts: 101
Joined: 2019-05-26 18:38

Re: Reset, or clear field after save changes

Post by dharbitindy » 2020-04-02 17:41

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.

dharbitindy
Veteran Member
Posts: 101
Joined: 2019-05-26 18:38

Re: Reset, or clear field after save changes

Post by dharbitindy » 2020-04-02 21:52

pböttcher's code was of course spot on. The problem was with a file on my end. Thank you for the expertise!

David

Post Reply