StratusForms
StratusForms copied to clipboard
Unable to save blank values
I am trying to save a form and sometimes I need to change from a non-blank value to a blank value. For most types I can just use a space which is close enough to being a blank that I can get by with it, but for dates it doesn't work - the validation fails.
QUESTION: Why is saving of blank values not supported?
SUGGESTION: Make the following change (original line commented out and replaced in the following edited line)
function buildStratusFormsDataObject(formElement,StratusFormsValuePairs) {
console.log('buildStratusFormsDataObject(): enter formElement=',formElement,'StratusFormsValuePairs=',StratusFormsValuePairs);
var formDataObject = {};
$(formElement).find("input").not(".SFDontSave").each(function () {
var id = this.id.split("0sfrepeat0")[0];
if (id.indexOf("TopSpan_HiddenInput") < 0) {
var value = $(this).val();
var encryptField = $(this).hasClass(gStratusFormsEncryptClass);
var encodedValue = htmlEncode(value, encryptField);
var type = $(this).attr("type");
if (type == undefined) {
type = "text";
}
// if (value != undefined && value.length > 0 && type.toUpperCase() != "BUTTON") {
if (value != undefined && type.toUpperCase() != "BUTTON") {
formVal = formVal = $(this).attr("listFieldName");
I forgot the related change that had to be made as well:
in the same function:
function buildStratusFormsDataObject(formElement,StratusFormsValuePairs) {
this change needs to be made:
if (formVal != undefined) {
// PLB changed this:
// if ($(this).attr("isDate") == "yes") {
// PLB to this:
if ($(this).attr("isDate") == "yes" && value) {
// PLB end change
var thisDate = new Date(value);
value = thisDate.toISOString();
}
If this change is not made then a "blank" date becomes a 1/1/1970 date.
So I noticed a new release just recently and this didn't make it in... Would you prefer if I were to provide a pull request or something like that? Or do you have concerns with the accuracy of the suggested code change (if so, you're the expert - just tell me what you're concerned about and I'll try to fix it)
If you are concerned about backward compatibility, what about if you checked for the class "AllowEmptyDate" or something like that - if that class is there then save an empty date; if it's not there then don't save anything to maintain backward compatibility. (Again, I'd be happy to provide a pull request if that would help.)
https://github.com/plbowers/StratusForms/pull/1
It LOOKS like this was mostly fixed in 1.55, although I did find a bug when testing. Pull the lastest 1.55 and see if it works for you please.