Permalink
Browse files

Fixed an issue that Ajax requests of the `select2` custom field type …

…could not retrieve responses for the factory classes other than the admin page. Resolves #258.

- Changed the Ajax request url to `wp-admin/admin-ajax.php`.
- Changed the minimum required version of Admin Page Framework to 3.8.14.
- Supported fields of factories other than admin pages.
  • Loading branch information...
michaeluno committed Jan 13, 2017
1 parent f4e9c13 commit c76f4cc48519a8582c27443aa04b0e39995c9f7e
@@ -75,9 +75,9 @@
* </ul>
*
* @since 3.8.7
- * @version 0.0.2b
+ * @version 0.0.3
* @supports IE8 or above. (uses JSON object)
- * @requires Admin Page Framework 3.8.8
+ * @requires Admin Page Framework 3.8.14
*/
class Select2CustomFieldType extends AdminPageFramework_FieldType_select {
@@ -123,8 +123,7 @@ class Select2CustomFieldType extends AdminPageFramework_FieldType_select {
);
- protected function construct() {
- }
+ protected function construct() {}
/**
* Loads the field type necessary components.
@@ -164,6 +163,7 @@ protected function getEnqueuingStyles() {
*/
protected function getScripts() {
+ $_sAjaxURL = admin_url( 'admin-ajax.php' );
$_aJSArray = json_encode( $this->aFieldTypeSlugs );
return
"jQuery( document ).ready( function(){
@@ -280,13 +280,14 @@ protected function getScripts() {
_aOptions, // user inputs
{
ajax: {
- // url: the current page
+ url: '{$_sAjaxURL}',
dataType: 'json',
type: 'POST', // as `page` query key conflicts with page slug, do not use `GET`.
- data: function (params) {
+ data: function (params) {
params.page = params.page || 1;
return {
// Query Parameters
+ action: 'dummy_select2_field_type_action',
q: params.term, // search term
page: params.page, // pagination number
doing_select2_ajax: true, // ensure it is called from here
@@ -347,8 +348,9 @@ protected function getScripts() {
*/
jQuery.ajax( {
type: 'POST',
- // url: url, // omit so that the current url is used
+ url: '{$_sAjaxURL}',
data: {
+ action: 'dummy_select2_field_type_action',
tag: _sTerm,
doing_select2_ajax: true, // ensure it is called from here
field_id: _oSelect2Target.data( 'field_id' ), // will be checked in the background
@@ -596,9 +598,9 @@ protected function getStyles() {
*/
public function getField( $aField ) {
- $_sInputForEncodedVelue = '';
+ $_sInputForEncodedValue = '';
if ( is_callable( $this->getElement( $aField, array( 'callback', 'search' ) ) ) ) {
- $_sInputForEncodedVelue = $this->_getChildInputByKey( 'encoded', $aField );
+ $_sInputForEncodedValue = $this->_getChildInputByKey( 'encoded', $aField );
$aField[ 'attributes' ] = $this->_getAttributesUpdatedForAJAX( $aField );
}
@@ -612,7 +614,7 @@ public function getField( $aField ) {
+ $this->getElementAsArray( $aField, array( 'attributes', 'select', ) );
return parent::getField( $aField ) // the select field
- . $_sInputForEncodedVelue; // a nested input that stores an encoded selection value.
+ . $_sInputForEncodedValue; // a nested input that stores an encoded selection value.
}
@@ -1,6 +1,13 @@
# Change Log
+
+= 0.0.3 - 2017/01/11 =
+- Changed the Ajax request url to `wp-admin/admin-ajax.php`.
+- Changed the minimum required version of Admin Page Framework to 3.8.14.
+- Supported fields of factories other than admin pages.
+
= 0.0.2b - 2016/10/24 =
- Set a field type slug to the register callback function to avoid unnecessary callback function calls.
-- Made it compatible with Admin Paqe Framework 3.8.8.
+- Made it compatible with Admin Page Framework 3.8.8.
+
= 0.0.1b =
- Released. Uses Select2 v4.0.3.
View
@@ -289,10 +289,10 @@ In order to use a custom field type, you need to instantiate the field type clas
new Select2CustomFieldType( 'MyPlugin_AdminPageFramework' );
`
-Do this in the `load()` method in your extended framework class.
+Do this in the `setUp()` method in your extended framework class.
`
-public function load() {
+public function setUp() {
new Select2CustomFieldType( 'MyPlugin_AdminPageFramework' );
}
`
@@ -509,6 +509,7 @@ See examples, https://gist.github.com/michaeluno/c30713fcfe0d9d45d89f, https://g
- Added the `load()` methods to factory classes of post/page meta boxes, user/taxonomy meta.
- (minor breaking change) Deprecated the parameter of the `load()` method of the widget factory class.
- Changed the behaviour of not loading form components in `admin-ajax.php` so that custom field types can access `admin-ajax.php` using Ajax.
+- Fixed an issue that Ajax requests of the `select2` custom field type could not retrieve responses for the factory classes other than the admin page.
= 3.8.13 - 2016/12/22 =
- Added the `disabled` repeatable section and repeatable field arguments.

0 comments on commit c76f4cc

Please sign in to comment.