jqh 5 years ago
parent
commit
432dde5f6a
1 changed files with 4 additions and 5 deletions
  1. 4 5
      src/Form/Field/Tags.php

+ 4 - 5
src/Form/Field/Tags.php

@@ -171,12 +171,11 @@ class Tags extends Field
      *
      * @return $this
      */
-    public function ajax(string $url, string $idField = 'id', string $textField = 'name')
+    public function ajax(string $url, string $idField = 'id', string $textField = 'text')
     {
         $url = admin_url($url);
 
         $this->ajaxScript = <<<JS
-
   ajax: {
     url: "$url",
     dataType: 'json',
@@ -193,8 +192,8 @@ class Tags extends Field
 
       return {
         results: $.map(data.data, function (d) {
-                   d.id = d.$idField;
-                   d.text = d.$textField;
+                   d.id = d.{$idField};
+                   d.text = d.{$textField};
                    return d;
                 }),
         pagination: {
@@ -229,7 +228,7 @@ JS;
         if ($this->keyAsValue) {
             $options = $value + $this->options;
         } else {
-            $options = array_unique(array_merge($value, $this->options));
+            $options = array_unique(array_merge($value, (array) $this->options));
         }
 
         return parent::render()->with([