diff --git a/lizmap/modules/lizmap/lib/Form/QgisFormControl.php b/lizmap/modules/lizmap/lib/Form/QgisFormControl.php index 28c4ad05dd..9dab55ca45 100644 --- a/lizmap/modules/lizmap/lib/Form/QgisFormControl.php +++ b/lizmap/modules/lizmap/lib/Form/QgisFormControl.php @@ -506,14 +506,35 @@ protected function fillControlDatasource() case 'ValueMap': $valueMap = $this->properties->getValueMap(); if (is_array($valueMap)) { - // remove the QGIS null value if the control value is not - // required, as the widget will have a possibility to choose - // no value (so null value... ?) - if (!$this->required - && $this->fieldDataType == 'boolean' - && isset($valueMap[self::QGIS_NULL_VALUE]) - ) { - unset($valueMap[self::QGIS_NULL_VALUE]); + // Override values for boolean + if ($this->fieldDataType == 'boolean') { + // remove the QGIS null value if the control value is not + // required, as the widget will have a possibility to choose + // no value (so null value... ?) + if (!$this->required + && isset($valueMap[self::QGIS_NULL_VALUE]) + ) { + unset($valueMap[self::QGIS_NULL_VALUE]); + } + // transform values from QGIS ValueMap to Postgres Boolean + $booleanValues = array(); + foreach ($valueMap as $v => $label) { + $strV = strtolower($v); + if ($v === self::QGIS_NULL_VALUE) { + $booleanValues[self::QGIS_NULL_VALUE] = $label; + } elseif ($strV === 'true' || $strV === 't' + || intval($v) === 1 || $strV === 'on') { + // Postgres true + $booleanValues['t'] = $label; + } elseif ($strV === 'false' || $strV === 'f' + || intval($v) === 0 || $strV === 'off') { + // Postgres false + $booleanValues['f'] = $label; + } else { + $booleanValues[$strV] = $label; + } + } + $valueMap = $booleanValues; } // we don't use array_merge, because this function reindexes keys if they are // numerical values, and this is not what we want. diff --git a/tests/end2end/cypress/integration/form_edition_all_field_type-ghaction.js b/tests/end2end/cypress/integration/form_edition_all_field_type-ghaction.js index fce0961620..6d45ef8372 100644 --- a/tests/end2end/cypress/integration/form_edition_all_field_type-ghaction.js +++ b/tests/end2end/cypress/integration/form_edition_all_field_type-ghaction.js @@ -103,19 +103,6 @@ describe('Form edition all field type', function() { cy.get('#lizmap-edition-message').should('be.visible') }) - it('boolean, dropdown menu', function () { - // `boolean_nullable` should show a dropdown menu with : - // * an empty value - cy.get('#jforms_view_edition_boolean_nullable').select('') - cy.get('#jforms_view_edition_boolean_nullable').should('have.value', '') - // * a true value - cy.get('#jforms_view_edition_boolean_nullable').select('True') - cy.get('#jforms_view_edition_boolean_nullable').should('have.value', 'true') - // * a false value - cy.get('#jforms_view_edition_boolean_nullable').select('False') - cy.get('#jforms_view_edition_boolean_nullable').should('have.value', 'false') - }) - it('boolean, not null', function () { cy.get('#jforms_view_edition_boolean_notnull_for_checkbox').should('have.class', 'jforms-ctrl-checkbox') cy.get('#jforms_view_edition__submit_submit').click() diff --git a/tests/units/classes/Form/QgisFormControlTest.php b/tests/units/classes/Form/QgisFormControlTest.php index e4fb9b4c9b..520b89d2b1 100644 --- a/tests/units/classes/Form/QgisFormControlTest.php +++ b/tests/units/classes/Form/QgisFormControlTest.php @@ -367,9 +367,9 @@ public function testConstructCheckbox() $this->assertEquals($control->fieldDataType, 'boolean'); $this->assertEquals($control->fieldEditType, 'CheckBox'); $this->assertEquals($control->ctrl->getWidgetType(), 'checkbox'); - $this->assertEquals($control->ctrl->valueOnCheck, 'true'); + $this->assertEquals($control->ctrl->valueOnCheck, 't'); $this->assertEquals($control->ctrl->valueLabelOnCheck, 'Yes'); - $this->assertEquals($control->ctrl->valueOnUncheck, 'false'); + $this->assertEquals($control->ctrl->valueOnUncheck, 'f'); $this->assertEquals($control->ctrl->valueLabelOnUncheck, 'No'); } }