possible regression with Editor.dependent() 1.6.1

possible regression with Editor.dependent() 1.6.1

loukinglouking Posts: 259Questions: 52Answers: 0

This is related to https://datatables.net/forums/discussion/38027/use-of-options-instead-of-dependant

At least my code has regressed. Not sure if I was doing something nonstandard or not to cause this. I am sending you credentials by email so you can access http://sandbox.scoretility.com/raceresultservices

In this page with Editor 1.5.5, when clicking New, the first select would have values from http://sandbox.scoretility.com/servicecredentials Service Name field, through retrieving by ajax.

In 1.5.5, dataTables.editor.js code starting at line 2260 fires, but in 1.6.1 code starting at 2446 does not.

Because of the way my code is structured it's inconvenient for me to have both releases running at the same time. Let me know if I need to put 1.5.5 online for you to compare behavior.

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    It would appear that there is an incompatibility with Selectize and how Editor 1.6 handles the dependent() method. Selectize doesn't appear to allow the change event to bubble up the DOM, which is stopping Editor from seeing it.

    Could you try adding:

    focus: function ( conf ) {
      var select = conf._input;
    
      select.parents('div.DTE_Field').triggerHandler('focus');
    }
    

    to the Selectize plug-in please? I think that should resolve the issue.

    Allan

  • loukinglouking Posts: 259Questions: 52Answers: 0
    edited December 2016

    Hmm. I pull selectize from a cdn. Is there a way to patch this externally? I can probably figure it out, but I figure while I have your attention...

    :)

    Thanks for the quick response.

    (checking) Is it just

    $.extend(Selectize.prototype, {
       focus: function ( conf ) {
          var select = conf._input;
     
          select.parents('div.DTE_Field').triggerHandler('focus');
       }
    });
    

    before editor fieldtype selectize is pulled in?

  • loukinglouking Posts: 259Questions: 52Answers: 0
    edited December 2016

    I can put this on my sandbox if you need it, but from development when I patch as such, I get undefined error for conf at line 2857 of selectize from another view on initialization

    Note at line 2857, selectize is calling focus with no parameters from within open()

       self.focus();
    
    Uncaught TypeError: Cannot read property '_input' of undefined
        at Selectize.focus (selectize_editor_patch.js?v=1482840714:4)
        at Selectize.open (selectize.js?v=0.12.4:2857)
        at Selectize.refreshOptions (selectize.js?v=0.12.4:2288)
        at Object._addOptions (editor.selectize.js?v=1439582022:74)
        at Editor.create (editor.selectize.js?v=1439582022:94)
        at Editor.Field._typeFn (dataTables.editor.js?v=1482403410:753)
        at Editor.Field (dataTables.editor.js?v=1482403410:277)
        at Editor.add (dataTables.editor.js?v=1482403410:1871)
        at Editor.add (dataTables.editor.js?v=1482403410:1851)
        at Editor._constructor (dataTables.editor.js?v=1482403410:4186)
    

    and from http://sandbox.scoretility.com/raceresultservices when I focus on the selectize

    Uncaught TypeError: Cannot read property '_input' of undefined
        at Selectize.focus (selectize_editor_patch.js?v=1482840714:4)
        at Selectize.open (selectize.js?v=0.12.4:2857)
        at Selectize.onMouseDown (selectize.js?v=0.12.4:1508)
        at HTMLDivElement.mousedown (selectize.js?v=0.12.4:1314)
        at HTMLDivElement.dispatch (jquery-1.11.3.js?v=1.11.3:4670)
        at HTMLDivElement.elemData.handle (jquery-1.11.3.js?v=1.11.3:4338)
    
  • loukinglouking Posts: 259Questions: 52Answers: 0

    Also not sure if you want to override default selectize focus behavior

            /**
             * Gives the control focus.
             */
            focus: function() {
                var self = this;
                if (self.isDisabled) return;
        
                self.ignoreFocus = true;
                self.$control_input[0].focus();
                window.setTimeout(function() {
                    self.ignoreFocus = false;
                    self.onFocus();
                }, 0);
            },
    
  • loukinglouking Posts: 259Questions: 52Answers: 0

    Sorry, now I see your meaning was to edit FieldType-Selectize plugin. I will make this update and put on sandbox in a couple of hours. Trying to do now before I run, but am having some difficulty which I can't debug right now.

  • loukinglouking Posts: 259Questions: 52Answers: 0
    edited December 2016

    I spent a little more time, and was able to debug my problem. Unfortunately adding the focus method to FieldType-Selectize did not resolve the original problem. See http://sandbox.scoretility.com/raceresultservices

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Darn - it got 90% of the way there. In the Editor Javascript could you also change:

    if ( $.inArray( e.target, field.input().toArray() ) === -1 ) {
    

    to be:

    if ( $.inArray( e.target, field.node().toArray() ) === -1 ) {
    

    Sorry I haven't been able to check this. Normal service resumed in the early new year :smile:.

    Allan

  • loukinglouking Posts: 259Questions: 52Answers: 0
    edited December 2016

    Sorry not quite there yet. Did I patch this correctly? Note this is not urgent, and if it needs to wait until you have more time, that will be fine. This can be seen at http://sandbox.scoretility.com/raceresultservices

    Uncaught TypeError: field.node(...).toArray is not a function
        at HTMLDivElement.<anonymous> (dataTables.editor.selectizefix.js?v=1482934060:2448)
        at HTMLDivElement.dispatch (jquery-1.11.3.min.js?v=1.11.3:4)
        at HTMLDivElement.r.handle (jquery-1.11.3.min.js?v=1.11.3:4)
        at Object.trigger (jquery-1.11.3.min.js?v=1.11.3:4)
        at m.fn.init.triggerHandler (jquery-1.11.3.min.js?v=1.11.3:4)
        at Editor.focus (editor.selectize.js?v=1482844556:130)
        at Editor.Field._typeFn (dataTables.editor.selectizefix.js?v=1482934060:753)
        at Editor.Field.focus (dataTables.editor.selectizefix.js?v=1482934060:414)
        at Editor._focus (dataTables.editor.selectizefix.js?v=1482934060:4880)
        at Editor.open (dataTables.editor.selectizefix.js?v=1482934060:3318)
    
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    You did - my code was in error - sorry!

    if ( $.inArray( e.target, [ field.node() ] ) === -1 ) {
    

    I forgot what the return type from the field().node() method was.

    Allan

  • loukinglouking Posts: 259Questions: 52Answers: 0

    yup, that did the trick.

    will that be in 1.6.2?

    also will you update FieldType-Selectize plugin so I can download an official version? (too bad these are not available on cdn or with version number, though)

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    It probably will be, but I'd like to do some regression testing before committing to that. Otherwise there might be a regression of the regression...

    Thanks for the feedback on this.

    Allan

  • loukinglouking Posts: 259Questions: 52Answers: 0

    Thanks. Here is where using git issues to track datatables problems would be helpful, as I could link my issue https://github.com/louking/rrwebapp/issues/301 to yours and would know when to take the new release.

    But I understand you have a process, that these forums are very searchable, and that having issues as well divides where information is available.

    When this is fixed, would you be coming back to this thread to indicate as such?

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Yes - I'll update this thread when I've committed the fix.

    Allan

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    I've finally gotten around to this - way later than expected - sorry!

    The line I suggested above did indeed cause other issues. This is the one I've committed:

    if ( $( field.node() ).find( e.target ).length === 0 ) {
    

    Basically a change event caused by something inside the field's container will trigger a dependent action.

    I'm working on the remaining changes for 1.6.2 just now and it shouldn't be that far away.

    Regards,
    Allan

This discussion has been closed.