This page contains notes derived from tech questions asked of APF’s developer.
Code from the Field Type Pack
They are in the directory admin-page-framework-field-
About changing the size of the date field in a widget
You may use the ‘attributes’ argument to set inline CSS rules to the input tag.
'attributes' => array( 'style' => 'width: 60%', ),
About setting the month in the widget
Date setting is odd. For example, if you set new Date( 2015, 12, 25 ), the date picker will display January 26, 2016. The month is always off by one. Apparently the JavaScript standard for month notation is zero-based, so months are 0-11. I know. Dumb, right? In any case, to get it right, make sure the month number is one less than the actual month number. Here’s the JavaScript date object definition.
About setting date defaults
My problem statement was “I’d like the date field to appear with a pre-set date when the widget opens. I’ve tried using default and value, and I don’t seem to be able to make it do much of anything. In addition, I’d like the pop-up calendar to pop on that preset date, but it always opens on today’s date.”
To set a default value, you need to use the ‘default’ argument. To set a preset date marked in the pop-up date picker UI, you can use the `defaultDate` option of the datepicker jQuery plugin. The field type accepts the plugin options in the `options` argument. You would set it like this.
array( // Single date picker 'field_id' => 'date', 'title' => __( 'Date', 'admin-page-framework-field-type-pack' ), 'type' => 'date', 'default' => '2015/02/26', 'options' => '{ defaultDate: new Date( 2015, 2, 20 ), }', ),
A JavaScript array is passed to the options argument, not PHP’s. Good JavaScript resource page on date-time pickers. The JavaScript date picker API.
About setting multiple option lines
'options' => '{ numberOfMonths: 2, defaultDate: new Date( 2015, 2, 20 ), }',
About field_id naming in date fields
If the id field in ‘field_id’ has an underscore in it, the date picker doesn’t show up right. So use ‘targetdate’ and not ‘target_date’.
array( // Repeatable date picker fields 'field_id' => 'targetdate', // don't use dashes in the field id 'title' => __( 'Countdown target date', 'admin-page-framework-field-type-pack' ), 'type' => 'date', 'repeatable' => true, 'default' => 'December 25, 2015', 'options' => $jQuery_options, 'description' => __( 'If you choose multiple dates, the counter will reset after each.', 'admin-page-framework-field-type-pack' ), 'attributes' => array('style' => 'width:60%'), )
About using the EDD software licensing field type
According to the developer, “The ‘edd_software_licensing’ field type does not have a demo page. You use it like this:”
$this->addSettingFields( $this->sSectionID, // the target section id array( 'field_id' => 'field_type_pack_license', 'type' => 'edd_software_licensing', 'store_uri' => YOUR_STORE_URI, 'product_name' => YOUR_PRODUCT_NAME, 'title' => __( 'License Activation', 'admin-page-framework-field-type-pack' ), ) );
He says, “You would change the part YOUR_STORE_URI and YOUR_PRODUCT_NAME to yours. The field type pack itself uses that field type. You can check the actual usage in the file, admin-page-framework-field-type-pack/include/class/admin/setting/AdminPageFrameworkFieldTypePack_Setting_License.php.”