1

Below is a function which is called in my alpaca "postRender" callback :

function onClickDefaultParameterButtons(renderedForm) {
    $('#paramFormSaveBtn')
        .click(
                function() {
                    if (renderedForm.isValid(true)) {
                        val = renderedForm.getValue();

                        paramIdDefaultMap[curParameterIdSelect].Parameter.Value = JSON
                                .stringify(val);

                        genericJsonAjaxCall(
                                "${RestUrlBase}/DefaultParameters/"
                                        + curParameterIdSelect,
                                "put",
                                JSON.stringify(paramIdDefaultMap[curParameterIdSelect]),
                                saveDefaultParameterChangesSuccessCallback,
                                false);

                    }
                });
}

I have a checkbox in this form and it has some issues with serialization.

For example, if the checkbox is checked, it will show up as a value in the renderedForm.getValue() return.

If the checkbox is not checked, it will not show up as a value in the renderedForm.getValue() return.

Another issue I found is when I have a number field and put the value of 0, it also does not show up in the renderedForm.getValue(). I need all form values to show up whether they are checked, not checked or even 0.

Is there a way to get around this?

anon
  • 4,578
  • 3
  • 35
  • 54
Michael LoCicero
  • 423
  • 1
  • 5
  • 11
  • When using POST this is unfortunately the browser behaviour so not sure you can use POST and find a way around that. See http://stackoverflow.com/questions/11424037/does-input-type-checkbox-only-post-data-if-its-checked Can't remember if GET send them or not. – GillesC Jun 10 '14 at 14:03

1 Answers1

0

Others have said that POST/GET behaviour of the browser is to blame, but that's not the case for raw JSON serialization. You should be able to serialize your data and POST the raw JSON result to some service without a problem. The way a browser encodes form elements is not relevant to that.

The problem is in the alpaca's serialization code itself, where fields are only added if their value would pass this statement:

if (assignedValue)
{
    o[propertyId] = assignedValue;
}

So, if assignedValue is 0, or false, it won't be serialized. This is different than expected behaviour, which I think makes it a bug.

I have forked the alpaca code to handle this serialization as you (and I) would expect. A pull request is pending. Feel free to use it as is:

https://github.com/tylerperyea/alpaca

Or just change this contents of the js/fields/basic/ObjectField.js file, and rebuild.

You may also comment on the issue:

https://github.com/gitana/alpaca/issues/158

Tyler Peryea
  • 523
  • 4
  • 11