These are chat archives for ThoughtWorksInc/Binding.scala

29th
Nov 2018
Mustafa Kuscu
@mcku
Nov 29 2018 22:10

@mcku "i have tried what you have suggested some time ago, and did not work" Are you sure what problem was in initialization and not in missing watch/render/bind or something like this? In our case initialization after creation works well with https://getmdl.io/ and https://materializecss.com

@glmars I think my conclusion is wrong and jQuery can access the element. And your proposal is very elegant and valuable.
However, it's not done yet. dom.scala thinks it is inserting the element twice and throws an exception. But by tracing, i can confirm that the method is entered just once.
The element is here https://gist.github.com/glmars/a597f7c28931a38e2e9b3262279889a9#file-dropdown-initialize-scala-L17
And here is the exception: https://github.com/ThoughtWorksInc/Binding.scala/blob/v11.3.0/dom/src/main/scala/com/thoughtworks/binding/dom.scala#L106

message is: "Cannot insert SELECT twice!"

Any ideas? I have traced through debugger and it enters only once into the JQuery call. And there is only one jquery instance, as seen by the inspector.
Mustafa Kuscu
@mcku
Nov 29 2018 22:32
Oh.. i think the example happened to be a corner case. because the <select>...</select> was being transformed into a <div>...</div> by jquery on the fly. and perhaps this is confusing the internals of binding.dom.
Mustafa Kuscu
@mcku
Nov 29 2018 22:38

and it is successful if the element is not initially specified as a select and dynamically contructed, instead if specified as something already html div like this (which is as legit as the previous one)

val simple = <div class="ui selection dropdown">
  <input type="hidden" name="gender"/>
  <i class="dropdown icon"></i>
  <div class="default text">Gender</div>
  <div class="menu">
    <div class="item" data-value="1">Male</div>
    <div class="item" data-value="0">Female</div>
  </div>
</div>

yay, it works ;)