? Success

User tests: Successful: Unsuccessful:

avatar okonomiyaki3000
okonomiyaki3000
29 Nov 2013

This PR replaces #2429 which was to master instead of staging.

Tracker: http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=32564&start=0

This change first of all simplifies an unnecessarily verbose if/else block. That part of the change affects only code readability, there is no change whatsoever to functionality at this point.

Then, if the field handles multiple values but no value has been set, the value is set to empty array. This way, if the field has one or more default values but the user chooses to deselect them, the field will not reselect the default values when the form is loaded again in the future.

avatar okonomiyaki3000 okonomiyaki3000 - open - 29 Nov 2013
avatar okonomiyaki3000 okonomiyaki3000 - change - 26 Jun 2014
Title
Save empty multi-value fields as empty array (instead of not at all).
[#32564] Save empty multi-value fields as empty array (instead of not at all).
avatar okonomiyaki3000 okonomiyaki3000 - change - 26 Jun 2014
Title
Save empty multi-value fields as empty array (instead of not at all).
[#32564] Save empty multi-value fields as empty array (instead of not at all).
avatar okonomiyaki3000
okonomiyaki3000 - comment - 25 Jul 2014

There are instructions in the tracker but I guess maybe some people didn't get it.

Setup

  • Create a form with a checkboxes field where one or more of the boxes are checked by default.
  • Uncheck all boxes and save the form.
  • Open the form again.

Before

After saving with and empty selection, Joomla will reset the field to the default values (in which one or more boxes are checked). So there's no way to select none in this case.

After

You will be able to deselect all.

avatar nicksavov nicksavov - change - 21 Aug 2014
Labels Removed: ?
avatar brianteeman brianteeman - change - 21 Aug 2014
Status New Pending
avatar jissues-bot jissues-bot - change - 17 Oct 2014
Title
[#32564] Save empty multi-value fields as empty array (instead of not at all).
Save empty multi-value fields as empty array (instead of not at all).
avatar brianteeman brianteeman - change - 17 Oct 2014
Title
[#32564] Save empty multi-value fields as empty array (instead of not at all).
Save empty multi-value fields as empty array (instead of not at all).
avatar okonomiyaki3000 okonomiyaki3000 - change - 20 Nov 2014
Title
Save empty multi-value fields as empty array (instead of not at all).
[#32564] Save empty multi-value fields as empty array (instead of not at all).
avatar okonomiyaki3000 okonomiyaki3000 - change - 20 Nov 2014
Title
Save empty multi-value fields as empty array (instead of not at all).
[#32564] Save empty multi-value fields as empty array (instead of not at all).
avatar roland-d
roland-d - comment - 2 May 2015

@test: Works as expected. After applying the patch, multi-checkbox values are handled correctly.

Now, it took me some time to get a good test case, so here is to help out the next guy/girl:

  1. Create a field called test in the user table. Replace pvrn4 to your own prefix

    ALTER TABLE `pvrn4_users`
    ADD COLUMN `test` VARCHAR(50) NOT NULL DEFAULT '0' AFTER `requireReset`;
  2. Add this code to the file administrator\components\com_users\models\forms\user.xml

    <field name="test"
               type="checkboxes"
               multiple="true"
                default="a,b,c">
            <option value="a">A</option>
            <option value="b">B</option>
            <option value="c">C</option>
            <option value="d">D</option>
            <option value="e">E</option>
            <option value="f">F</option>
        </field>
  3. Add this line to the file libraries\joomla\user\user.php after line 709:

        $this->test = json_encode($this->test);
  4. Add this line to the file administrator\components\com_users\models\user.php after line 78:

        $result->test = json_decode($result->test);
  5. Go to the url: administrator/index.php?option=com_users&view=users
  6. Edit an existing user and you will see the checkboxes where a,b,c are pre-checked.
  7. Without the patch the value in the test field in the database is a mess
  8. After applying the patch, the data in the test field is as expected.
avatar roland-d roland-d - test_item - 2 May 2015 - Tested successfully
avatar zero-24
zero-24 - comment - 2 May 2015

@test Works as expected. Thanks.

Also thanks for the good instructions by @roland-d moving to RTC here :smile:

avatar zero-24 zero-24 - change - 2 May 2015
Category Libraries
avatar zero-24 zero-24 - change - 2 May 2015
Status Pending Ready to Commit
avatar zero-24 zero-24 - test_item - 2 May 2015 - Tested successfully
avatar zero-24 zero-24 - change - 2 May 2015
Labels Added: ?
avatar roland-d roland-d - close - 3 May 2015
avatar roland-d roland-d - change - 3 May 2015
Status Ready to Commit Closed
Closed_Date 0000-00-00 00:00:00 2015-05-03 06:03:37
Closed_By roland-d
avatar roland-d roland-d - close - 3 May 2015
avatar okonomiyaki3000 okonomiyaki3000 - head_ref_deleted - 1 Jun 2015
avatar Fedik Fedik - reference | b7a1de1 - 3 Jul 15

Add a Comment

Login with GitHub to post a comment