We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33968
    • 863 Posts
    I’m attempting my first CMP and thought I was doing well until I wanted to save a false value from a checkbox type field.

    Checking it works fine, returning the value ’1’ and saving it to the db.

    However, the checkbox mimics html checkbox behaviour in not returning a value when unchecked. In this case I need a value ’0’ to save into my database. Any ideas how to go about this?

    {
        xtype: 'checkbox'
        ,fieldLabel: _('active')
        ,name: 'active'
        ,inputValue: '1'
    }
    


    ps. I’ve used the ’combo-boolean’ type for now which works fine, but I would prefer to have the checkbox working!
      • 6228
      • 249 Posts
      There is no convenience parameter or method to send an unchecked checkbox value with Ext 3.3 (Ext 4.0, on the other hand, has a dandy parameter called [tt]uncheckedValue[/tt]).

      Here’s an older thread in Sencha’s forums that talks about using a hidden field to send a value depending on checked state:

      http://www.sencha.com/forum/showthread.php?113263-how-to-send-a-value-for-a-checkbox-when-it-is-unchecked

      Hope this helps
        lo9on.com

        MODx Evolution/Revolution | Remote Desktop Training | Development
        • 33968
        • 863 Posts
        Hi, thanks for the link - I’d seen some discussion on Sencha but hadn’t stumbled on a solution. I’m really not familiar with ExtJS but will have a crack at that suggestion!
        • I thought when browsing the code of 2.1-rc4 the other day there was some extension there that would force 0 to be sent when not checked, but not 100% sure on that. Was looking for something else.

          Anyway, I think the answer would be in your processor where you actually use the data (or lack thereof) to store in the db.

          It should be sending an empty key to your processor file, and you can use that to check it. Even better, use a syntax like this:
          $active = $modx->getOption('active',$scriptProperties,0);
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
            • 28215
            • 4,149 Posts
            Quote from: Mark at May 24, 2011, 12:45 PM

            I thought when browsing the code of 2.1-rc4 the other day there was some extension there that would force 0 to be sent when not checked, but not 100% sure on that. Was looking for something else.
            Yes, we added an xtype: ’xcheckbox’ that behaves exactly like a normal checkbox, except it sends 0 if unchecked.
              shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
              • 33968
              • 863 Posts
              Thanks guys, you seem to have everything covered!

              Cheers smiley
              • Quote from: splittingred at May 24, 2011, 12:48 PM

                Quote from: Mark at May 24, 2011, 12:45 PM

                I thought when browsing the code of 2.1-rc4 the other day there was some extension there that would force 0 to be sent when not checked, but not 100% sure on that. Was looking for something else.
                Yes, we added an xtype: ’xcheckbox’ that behaves exactly like a normal checkbox, except it sends 0 if unchecked.
                Doc-i-fied to make sure it doesn’t get lost in the forum: http://rtfm.modx.com/display/revolution20/MODExt#MODExt-xcheckbox
                  Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                  Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                  • 38290
                  • 712 Posts
                  Quote from: markh at May 24, 2011, 12:58 PM
                  Quote from: splittingred at May 24, 2011, 12:48 PM

                  Doc-i-fied to make sure it doesn't get lost in the forum: http://rtfm.modx.com/display/revolution20/MODExt#MODExt-xcheckbox

                  Very nice, just got stuck on this too and xcheckbox saved my bacon. No seriously, I'm cooking bacon right now.
                    jpdevries