Select2 With options in PHP

Select2 With options in PHP

wouterwouter Posts: 22Questions: 7Answers: 0

He all,

I'm running into an issue with the Select2 plugin. It works really well when i specify the options in the js editor field like so:

{
 label:             "client",
 name:          "contact_id",
 type:          "select2",
 opts:          {
    placeholder: "-- client --",
   allowClear: true,
   ajax: { 
     url: "/_data/lookup/",
     data: function(params){
       return { q: params.term, table: "client" }; 
       }, dataType: 'json', delay: 250
      }
} 
},

but when i specify the options in the php field like so:

Field::inst( 'project.contact_id', 'contact_id' )
  ->setFormatter( function ( $val, $data ) {
    return ($val != "" ? $val : NULL);
    })
  ->options( Options::inst()
  ->table( 'contact' )
  ->value( 'id' )
  ->label( 'name' )
  ->where( function ($q) { $q->where( 'is_client', '1', 'LIKE' ); } )
 ),

It used to work with previous version of the select2 field type plugin. But in the latest versions it gives an error caught TypeError: this.field is not a function. The problem is somewhere here i guess..

set: function ( conf, val ) {
 var field = this.field(conf.name);

Anyone what i'm doing wrong? or is select2 no longer compatible with options set in the php field?

Thanks!
Wouter

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,569Questions: 1Answers: 10,481 Site admin
    Answer ✓

    Hi Wouter,

    Apologies, I totally missed this thread before. I've added a reply about this issue in another thread discussing it.

    Regards,
    Allan

Sign In or Register to comment.