formHash function does not set the values if the value is empty string
| Project: | Field Plug-in |
| Version: | 0.7 |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | DanSwitzer2 |
| Status: | closed |
Jump to:
I am not sure about the behaviour.
I am using the plugin to store the form, and restore it back if needed,
unfortunatelly I have a input text box, which is empty, the state got saved perfectly,
but if the user enters some values into the form input box,
then I restore the state calling
$myForm.formHash(savedValues); it does not set the empty string on the element.
I checked the code. it is in line 288
} else if( !!inHash[n] ){
jel[defaults.useArray ? "fieldArray" : "setValue"](inHash[n]);
}I see the purpose was to avoid overwriting a value with an undefined in the hash.
although this unfortunately does not set the value if the value is in the hash but empty.
if the hash has something like this
{
myinputtext = ""
}this will also be skipped, I am not sure if this is the intended or a bug.
for me I need to set back the input box to it's empty state.
of course it can happen that the form has some elements that is not defined in the passed in hash. to sort this problem out I did the following ->
} else if( eval("inHash."+n) !== undefined ){
jel[defaults.useArray ? "fieldArray" : "setValue"](inHash[n]);
}I do not want to post this as a patch, as I am a java developper totally new to JS, and I am not sure this is the best solution to check if an assoc array has such a field or not.
I am looking forward to see a better solution.
Thanks a lot
Istvan

Comments
#1
I think this is nicer like this :)
} else if( inHash[n] !== undefined ){jel[defaults.useArray ? "fieldArray" : "setValue"](inHash[n]);
}
#2
This was actually fixed in v0.7.1 (which is on my site.)
#3