So let's try something else.
print(<TodoForm add_url=True/>)
mixt.exceptions.InvalidPropValueError:
<TodoForm>.add_url: `True` is not a valid value for this prop (type: <class 'bool'>, expected: <class 'str'>)
And it's the same if we pass True
in python
print(<TodoForm add_url={True}/>)
mixt.exceptions.InvalidPropValueError:
<TodoForm>.add_url: `True` is not a valid value for this prop (type: <class 'bool'>, expected: <class 'str'>)
Ok, let's trick the system and pass "True"
, as a string.
print(<TodoForm add_url="True"/>)
mixt.exceptions.InvalidPropValueError:
<TodoForm>.add_url: `True` is not a valid value for this prop (type: <class 'bool'>, expected: <class 'str'>)
Still the same, but here we passed a string! Yes but there are 4 values that are always evaluated to what they seems to be:
The only way to pass one of these values as a string, is to pass them via python, as a string:
print(<TodoForm add_url={"True"}/>)
<form method="post" action="True"><label>New Todo: </label><input type="text" name="todo" /><button type="submit">Add</button></form>
Except these 4 values, and numbers, every value that is passed to an attribute is considered a string. Even if there is no quotes, like in html in HTML5, where quotes are not mandatory for strings without some characters (no spaces, no /
...).
To pass something else, you must surround the value in curly braces (and in this cases there is no need for quotes around the curly braces.
Ok, now we are sure that we only accept string.... but what if I pass nothing? And... what is "nothing"?
Let's start with an empty string in python:
print(<TodoForm add_url={""}/>)
<form method="post" action=""><label>New Todo: </label><input type="text" name="todo" /><button type="submit">Add</button></form>
Ok it works, we wanted a string, we have a string.
Now let's pass this empty string directly:
print(<TodoForm add_url=""/>)
<form method="post" action=""><label>New Todo: </label><input type="text" name="todo" /><button type="submit">Add</button></form>
It still works, because it's still a string. Let's remove the quotes, to see.
print(<TodoForm add_url=/>)
mixt.exceptions.GeneralParserError: <mixt parser> Unclosed Tags: <TodoForm>
Hum yeah, this is not valid HTML. So let's remove the =
:
print(<TodoForm add_url/>)
mixt.exceptions.InvalidPropValueError:
<TodoForm>.add_url: `True` is not a valid value for this prop (type: <class 'bool'>, expected: <class 'str'>)
WHAT? Yes, think about HTML5 attributes like required
, checked
... They only need to be present as an attribute, without value, to be considered True
. So when an attribute doesn't have any value, it's a boolean, and it's True
.
In addition to not pass a value, those two other ways are valid in HTML5 for a boolean to by True
:
For your convenience, we added another way:
pass True
(case does not matter), as python or as a string: required=True
, required={True}
, required="true"
And its counterpart, to pass False
:
pass False
(case does not matter), as python or as a string: required=False
, required={False}
, required="false"