Forum Discussion
AlinMihalcea1
8 years agoQrew Assistant Captain
Dan, I am employing your solution ,but I have a question for you regarding the logging of check boxes. Below is an example of how the code is logging currently.
Can I have it say "Was = Off; now = On" ?
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
[NOV-06-17 8:39 AM XXX] ROM Confirmed Completion was =1; now =on
Ready To Invoice - Notify AR was =0; now =on
In AR Review was =0; now =on
Rejected By AR was =0; now =on
Can I have it say "Was = Off; now = On" ?
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
[NOV-06-17 8:39 AM XXX] ROM Confirmed Completion was =1; now =on
Ready To Invoice - Notify AR was =0; now =on
In AR Review was =0; now =on
Rejected By AR was =0; now =on
- _anomDiebolt_8 years agoQrew EliteSure this would be possible and would probably be trivial. But you would have to point me to my own example as I have so many it can become difficult to locate them without having a link or an obvious search strategy to find it.
- AlinMihalcea18 years agoQrew Assistant Captain$("#_fid_342").attr("readonly", "readonly");
var label, oldValue, newValue, log;
$("#_fid_243, #_fid_235, #_fid_237, #_fid_251, #_fid_239, #_fid_241, #_fid_259, #_fid_132").on("change", function() {
log = [];
_.each([243, 235, 147, 237, 251, 239, 259, 132], function(fid) {
oldValue = $("[name=_fid_oval_" + fid + "]").val();
newValue = $("#_fid_" + fid).val();
if (oldValue != newValue) {
label = $("label[for=_fid_" + fid + "]").text();
log.push(label + " was =" + oldValue + "; now =" + newValue);
}
});
$("#_fid_342").html(log.join("\n"));
}); - _anomDiebolt_8 years agoQrew EliteChange oldValue => (oldValue ? "on" : "off") as follows:
log.push(label + " was =" + (oldValue ? "on" : "off") + "; now =" + newValue); - AlinMihalcea18 years agoQrew Assistant CaptainDan I appreciate your help!
On last thing.
I would like for this to only say "On" or Off if it's a checkbox. The code is also logging text and number fields. - _anomDiebolt_8 years agoQrew EliteTry this (changed lines in bold):
$("#_fid_342").attr("readonly", "readonly");
var label, oldValue, newValue, log, type;
$("#_fid_243, #_fid_235, #_fid_237, #_fid_251, #_fid_239, #_fid_241, #_fid_259, #_fid_132").on("change", function() {
log = [];
_.each([243, 235, 147, 237, 251, 239, 259, 132], function(fid) {
oldValue = $("[name=_fid_oval_" + fid + "]").val();
newValue = $("#_fid_" + fid).val();
type = $("#_fid_" + fid).attr("type");
if (oldValue != newValue) {
label = $("label[for=_fid_" + fid + "]").text();
if (type == "checkbox") {
log.push(label + " was =" + (oldValue ? "on" : "off") + "; now =" + newValue);
} else {
log.push(label + " was =" + oldValue + "; now =" + newValue);
}
}
});
$("#_fid_342").html(log.join("\n"));
}); - AlinMihalcea18 years agoQrew Assistant CaptainDan,
this fix works as far as it seeing the difference between the checkbok and the rest, but the code doesn't seem to log the proper values for the checkboxes
see log below.
It doesn't matter what I change the checkbox to, it will say was on and now on. Also it seems to log all checkboxes, even the ones I don't change
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ROM Confirmed Completion was =on; now =on
Ready To Invoice - Notify AR was =on; now =on
In AR Review was =on; now =on
Rejected By AR was =on; now =on
Invoice Number was =21212; now =111111 - _anomDiebolt_8 years agoQrew EliteNormally I test everything before I post but I didn't in this case and I should have.
Checkboxes are a little different than other form elements as to how their on/off value is represented. To get the current state of a checkbox you have to use this jQuery which returns true or false:
$("#_fid_" + fid).prop("checked");
Don't use this code to get the value of a checkbox: newValue = $("#_fid_" + fid).val();
So you will have to refactor the code to test (1) the type of the control ("checkbox" vs "text"), (2) if the oldValue is equal to the newValue and from there push the appropriate message into the log array.
I am afraid that I don't have time to write the code and I could likely make another typo or oversight unless I worked from a live demo (and I don't have time for that either).- ChanceStorey5 years agoQrew MemberAny best-practice advice for 2021? Trying to follow directions but even when creating and utilizing my [-] field it seems like enough things have changed to where it's not as simple as following the directions that are on this thread.
- AlinMihalcea18 years agoQrew Assistant CaptainI understand.
As always, Thanks for your contributions!