We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44407
    • 3 Posts
    I have a custom resource with a custom database. My custom controller populates my update view correctly and everything is great. When I save an update form of my custom recource, everything is correctly saved to the database. great. The problem is I have has checkbox names "child_care" and it is "checked" on update view load correctly, but when I save the update view form, the extJS success callback calls "this.getForm().setValues(object);" which repopulates the fields with the now saved values. object['child_care'] holds the correct value, but it is being returned as a string instead of a boolean as it is on initial update view load. This unchecks the the "child_care" checkbox after save because the checkbox "checked" property evaluates a string as false. Is there a place in extJS model somewhere that I need to define "child_care" as a integer or boolean?

    record values on initial update view page load (i bolded the the child_care field)(these values are correct)

    {"id":25,"type":"document","contentType":"text/html","pagetitle":"test event 26","longtitle":"","description":"","alias":"te26","link_attributes":"","published":true,"pub_date":0,"unpub_date":0,"parent":0,"isfolder":true,"introtext":"","content":"Much stuff. Hello world.","richtext":true,"template":1,"menuindex":2,"searchable":true,"cacheable":true,"createdby":1,"createdon":"2014-09-26 16:52:27","editedby":1,"editedon":"2014-09-30 11:22:06","deleted":false,"deletedon":0,"deletedby":0,"publishedon":"2014-09-27 12:26:00","publishedby":1,"menutitle":"","donthit":false,"privateweb":false,"privatemgr":false,"content_dispo":0,"hidemenu":false,"class_key":"EventResource","context_key":"web","content_type":1,"uri":"","uri_override":false,"hide_children_in_tree":0,"show_in_tree":1,"properties":null,"content_id":25,"icon_path":"/res/icon.jpg","contact_id":1,"date_time":"2014-09-30 20:14:00","recurrence":"every Sunday","location_id":0,"cost":"$30 per person","child_care":true,"audience_id[]":"9","ministry_id[]":"18","syncsite":true,"resourceGroups":[],"create_resource_token":"542addd3c579a6.60573895","parent-cmb":0}


    these are the values that are applies in the success callback after save (i hit save when "child_care" was checked) (as you can see the value is correct but it needs to be a boolean like it is on ititial page load)

    {"id":25,"type":"document","contentType":"text/html","alias":"te26","published":true,"pub_date":0,"unpub_date":0,"parent":0,"isfolder":true,"richtext":true,"template":1,"menuindex":2,"searchable":true,"cacheable":true,"createdby":1,"createdon":"2014-09-26 16:52:27","editedby":1,"editedon":"2014-09-30 11:48:37","deleted":false,"deletedon":0,"deletedby":0,"publishedon":"2014-09-27 17:26:00","publishedby":1,"donthit":false,"privateweb":false,"privatemgr":false,"content_dispo":0,"hidemenu":false,"class_key":"EventResource","context_key":"web","content_type":1,"uri":"","uri_override":0,"hide_children_in_tree":0,"show_in_tree":1,"icon_path":"/res/icon.jpg","contact_id":"1","audience_id":["9"],"ministry_id":["18"],"date_time":"2014-09-30 20:14:00","recurrence":"every Sunday","location_id":"0","cost":"$30 per person","child_care":"1","create-resource-token":"542adee10508f2.04614976","reloaded":"0","parent-original":"0","parent-cmb":"","syncsite":1,"action":"resource/update","resource_groups":"[]"}


    my extjs "child_care" field

    Ext.override(MODx.panel.Resource,{
    	class_key: 'EventResource'
    	,defaultClassKey: 'EventResource'
    	,classLexiconKey: 'eventresource'
    	,getMainLeftFields: function(config) {
    		config = config || {record:{}};
    		return [{
    			xtype: 'xcheckbox'
    			,boxLabel: _('child_care')
    			,hideLabel: true
    			,description: _('child_care_help')
    			,name: 'child_care'
    			,id: 'modx-eventresource-child-care'
    			,inputValue: 1
    			,checked: parseInt(config.record.child_care)}
    		}];
    	}


    my custom resource database map

    <?php
    $xpdo_meta_map['erEvent']= array (
      'package' => 'eventresource',
      'version' => '1.1',
      'table' => 'er_event',
      'extends' => 'xPDOSimpleObject',
      'fields' => 
      array (
        'child_care' => 0,
      ),
      'fieldMeta' => 
      array (
        'child_care' => 
        array (
          'dbtype' => 'tinyint',
          'precision' => '1',
          'attributes' => 'unsigned',
          'phptype' => 'boolean',
          'null' => false,
          'default' => 0,
          'index' => 'index',
        )
      ),
    );
    ?>
    [ed. note: guitarcrazy44 last edited this post 11 years, 11 months ago.]
      • 11055 ☆ A M B ☆
      • 3,112 Posts
      sometimes, I revert it to 'checkbox' instead, and sideways, deal with non-existence value of the expected checkbox in processor.
        Rico
        Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
        MODx is great, but knowing how to use it well makes it perfect!

        www.virtudraft.com

        Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

        Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

        Maintainter/contributor of Babel

        Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.