// choice field object Zymonic.Field.Choice = function() {}; // do the inheritance Zymonic.Field.Choice.prototype = new Zymonic.Field.Field(); Zymonic.Field.Choice.prototype.constructor = this; // TODO: add other functionality to this // override getValue as ChoiceFields always have an input of value, hidden if display only Zymonic.Field.Choice.prototype.getValue = function() { value = this.jquery().val(); // apply any field fills var ffc_value = this.runFieldFillCalculations(value); // if value has changed then // set the changed value on the field itself so the user can see it if (ffc_value != null && ffc_value != value) { value = ffc_value; this.setValue(value, true); } return value; }; //override getValue to get list element, or the radio buttons Zymonic.Field.Choice.prototype.input_elements = function() { return this.container_div().find(":input[type='radio'], :input[type='checkbox'], select"); }; // override setValue to update checkboxes from hidden field value which gets set Zymonic.Field.Choice.prototype.setValue = function(value, not_as_changed) { // call super to set the hidden field value Zymonic.Field.Field.prototype.setValue.call(this, value, not_as_changed); // Need to handle select where we will need to set based on the display value var selectControl = this.container_div().find("select") if(selectControl.length) { $(selectControl).find("option").filter(function() { //may want to use $.trim in here return $(this).text() == value; }).prop('selected', true); } // if we are a checkbox update the checkbox from the hidden field var checkbox_container = this.container_div().find(".ChoiceCheckbox, .ChoiceButtons"); if (checkbox_container.length) { if (value) { if (checkbox_container.find(":checkbox[value='"+value+"'], :radio[value='"+value+"']").length) { checkbox_container.find(":checkbox[value='"+value+"'], :radio[value='"+value+"']").prop('checked', true); } else { var box_found = false; // Attempt to find it by display value if not by actual value var labels = this.container_div().find("label"); for (var i=0; i