react.rb

Can't set defaultValue using react.rb


My code is input(type: "text", name: "name", defalut_value: obj.name) and I try this too input(type: "text", name: "name", defalutValue: obj.name)

I always got <input type="text" name="name" data-reactid=".0.1.1.1.1"> with no "defalutValue"


Solution

  • Short answer: try defaultValue (not defalutValue) (you had a typo in the string)

    Long answer:

    React only passes along standard attributes or data attributes (like "data-foo") to built in tags everything else is scrubbed off. Standard attributes that have dashes, should be camel cased (i.e. defaultValue.)

    The camel casing is a bit inconsistent and is planned to be fixed in 0.9 BTW

    For now the rules are:

    1) for built in tags, only standard attributes or attributes beginning with "data-..." are passed along.

    2) if the html attribute has a dash (like default-value) the react attribute will be camel cased (like defaultValue) except for data- tags.

    3) For application defined components you need to use a legal ruby variable name, and class and style attributes are handled specially.

    Here is a working example http://goo.gl/abv28C