Trigger dependent with custom field of type "button"

Trigger dependent with custom field of type "button"

shatrughanshatrughan Posts: 87Questions: 16Answers: 0

Hi,
It has a reference to https://datatables.net/forums/discussion/34394 discussion.
The said thread contains the following suggestion from Mr. Allan

I am in urgent need of using dependent with custom field but unable to do so :disappointed: ...Please help solve the issue as per the above screeshot at the earliest.

Thanks & Regards
Shatrughan

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Sorry, I'm not clear what your issue/question is. Please can you update this to demonstrate, please,

    Colin

  • shatrughanshatrughan Posts: 87Questions: 16Answers: 0

    I have a custom field of type button coded as under -

    _fieldTypes.RO_Category = {
    create: function ( conf ) {
      var that = this;
     
      conf._enabled = true;
     
      // Create the elements to use for the input
      conf._input = $(
          '<div id="'+Editor.safeId( conf.id )+'">'+
              '<button type="button" style="margin-right:2px;" id="btn1" class="inputButton" value="TPDS" data-toggle="tooltip"  data-placement="top" title="Targetted Public Distribution System">TPDS</button>'+
              '<button type="button" class="inputButton" id="btn2" value="OWS"  data-toggle="tooltip"   data-placement="top" title="Other Welfare Schemes">OWS</button>'+
               '<button type="button" class="inputButton" id="btn3" value="OMSS" data-toggle="tooltip"  data-placement="top" title="Open Market Sale Scheme">OMSS</button>'+
               
          '</div>');
     
       
      $('button.inputButton', conf._input).click( function () {
          if ( conf._enabled ) {
              that.set( conf.name, $(this).attr('value') );
              }
     
          return false;
      } );
     
      return conf._input;
    },
     
    get: function ( conf ) {
      return $('button.selected', conf._input).attr('value');
    },
     
    set: function ( conf, val ) {
      $('button.selected', conf._input).removeClass( 'selected' );
      $('button.inputButton[value='+val+']', conf._input).addClass('selected');
    },
     
    enable: function ( conf ) {
      conf._enabled = true;
      $(conf._input).removeClass( 'disabled' );
    },
     
    disable: function ( conf ) {
      conf._enabled = false;
      $(conf._input).addClass( 'disabled' );
    }
    };
    

    Now, i need to show/hide other non-custom fields upon clicking on above custom field having three buttons using Dependent but it doesn't work since Dependent has no access with custom button.

    In a similar issue as I referenced and attached herein above, Allan had suggested some changes in code using input : function(conf) { } which return a node but i couldn't figure how that function be defind. Please look into and suggest to use Dependent with custom field.

    Regards,
    Shatrughan

  • shatrughanshatrughan Posts: 87Questions: 16Answers: 0

    As desired, the given link has been updated i.e. http://live.datatables.net/conekagu/3/edit?html,css,js,console,output
    Here, clicking on custom button 'Scheme' do nothing but it should have hidden the fields as mentioned in code.

    Please have a look and help resolve the issue.
    Shatrughan

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Hi,

    You need to trigger the change event in the set function:

      setTimeout( function () {
        conf._input.trigger( 'change', {editor: true} );
      }, 0 );
    

    should do it here.

    Allan

  • shatrughanshatrughan Posts: 87Questions: 16Answers: 0

    It works..Thanks Allan

This discussion has been closed.