Backbone.ModelBinder icon indicating copy to clipboard operation
Backbone.ModelBinder copied to clipboard

how does the converter work

Open cooolbasha opened this issue 10 years ago • 6 comments

Based on the radio button I wanted to show another field. so I used the converter to bind radio button + selector for the text with the converter. So when the radio button is clicked on, the converter function would call and it will be either hide or show based on the val passed(on/off). there are couple of issues

  1. the converter expects me to pass value back...which I am managing by passing model.get(text field)
  2. when I am setting some value to the text field(from the view). the converter is called..I was thinking the converter will be called only when there are change in the radio button because the binding[radiobutton] = [ {selector:[radiobutton]}, {converter:function(){},selector:[textbox]}. the binding is based on the radio button .some change to the radio button should trigger it..But here the change to text box is calling the converter function.

why cannot the converter have and option to quit processing based on the return values..as in this case the main intention is to just get the text field displayed. and why trigger when the other field values change...

cooolbasha avatar Jul 07 '14 02:07 cooolbasha

I am using the el attribute class to set/unset the show / hide..but I still feel that there should be ability to quit the converter when required./ there should be a option to have 1 field deciding the converter value..

cooolbasha avatar Jul 07 '14 02:07 cooolbasha

For age -> year conversion the converter is getting triggered 7 times ..when I set an value in the view

Bindings in Coffee Script
                @bindings.yob = [@bindings.yob].add
                        selector: "[name=age]"
                        converter: (direction,val,attr,model,selector)->
                            console.log 'arguments',arguments
                            return wed.CYEAR - val   #current year - year selected

Debugger/Console - when I changed the Yob to 1991

arguments ["ModelToView", "1991", "yob", User, Array[1]]
arguments ["ViewToModel", "23", "yob", User, Array[1]]
arguments ["ModelToView", 1991, "yob", User, Array[1]]
arguments ["ViewToModel", "23", "yob", User, Array[1]]
arguments ["ModelToView", 1991, "yob", User, Array[1]]
arguments ["ModelToView", 1991, "yob", User, Array[1]]
arguments ["ModelToView", "1991", "yob", User, Array[1]]

and the array is
 Array[1]  
   0: select#age.wed-init
   length: 1

It seems like it is working...But I don't know..how..

cooolbasha avatar Jul 07 '14 03:07 cooolbasha

is this repo active?

cooolbasha avatar Jul 12 '14 21:07 cooolbasha

Yes.it is active but I am not near a computer for another week...

theironcook avatar Jul 13 '14 04:07 theironcook

any updates

cooolbasha avatar Jul 23 '14 13:07 cooolbasha

Hi @cooolbasha, could you please put your example in a JSFiddle or similar? I want to look into this but it's really hard to follow exactly what you're trying to do. It's definitely possible to show/hide fields based on other model values, but I don't know what you're trying to do and what you're doing so I won't be a lot of help just yet. Please ping me back when you have the code in a JSFiddle and I'll take a look! :-)

platinumazure avatar Feb 08 '15 22:02 platinumazure