-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No bind function error #161
Comments
OK, so - In this case, what you want is |
Yes, I change the code with: /* add article */
router.get('/add', csrfProtection, function(req, res) {
var csrfToken = req.csrfToken();
var add_form = forms.create({
title: fields.string({ required: true }),
content: fields.password({ required: validators.required('请输入内容') }),
csrfToken:fields.string({ required: true, widget: widgets.hidden(),value: csrfToken})
}).bind({ fields:{ csrfToken: csrfToken }}).toHTML();
console.log(csrfToken);
res.render('articles/add',{
add_form:add_form
});
}); It's pass without error.But the problem is there is no value attribute there. Have I forget something? As my code before, I can't use hidden widget. Maybe you should change the readme.md, because it said there is a hidden widget. thanks again. |
The value generally comes with ".bind", not in the field definition itself. There is a hidden widget, but widgets aren't fields. I'll be happy to review a PR if you have an idea how to improve the docs! |
I use symfony framework before, It has a really good idea about form. $form = $this->createFormBuilder($task)
->add('task', 'text')
->add('dueDate', 'date')
->add('save', 'submit', array('label' => 'Create Task'))
->getForm(); 2, add attribute in the fields. $form = $this->createFormBuilder($task)
->add('task', 'text')
->add('dueDate', 'date', array('attr'=>array('value'=>$csrfToken, 'class'=>'test')))
->add('save', 'submit', array('label' => 'Create Task'))
->getForm(); 3, If you don't like writing php code, you can do it in Twig template also, like this: {{ form(form, {'attr': {'value': 'csrfToken'}}) }} Almost everything in field are attributes, It can easily add strange things in it. So frontend developer love this idea very much(Yes, I love it.). |
I'm familiar with PHP and symfony, but that's not the pattern we're going for here. The idea here is that you create the form and persist it across requests - and in each request and/or render, you use JS is a different language, shared mutable state is poison, and PHP patterns aren't often the ideal patterns to use in JS. |
Yes, I agree with you. Nodejs only have a thread. It's doesn't like PHP can have a lot of threads for a lot of users. So I am getting frustrating with nodejs. The logic is so complicate for me. Get back to the issue I still can't get the value attribute, Can you give me a example? /* add article */
router.get('/add', csrfProtection, function(req, res) {
var csrfToken = req.csrfToken();
var add_form = forms.create({
title: fields.string({ required: true }),
content: fields.password({ required: validators.required('请输入内容') }),
csrfToken:fields.string({ required: true, widget: widgets.hidden()})
}).bind({ fields:{ csrfToken: {value: csrfToken} }}).toHTML();
console.log(csrfToken);
res.render('articles/add',{
add_form:add_form
});
}); It does't work too. |
PHP usually has one thread too. It just has one per request, instead of one for everything. You want to create |
Maybe I have read a bad translated book. |
I am making a new form with this code:
But it turns out a "no bind function error":
But I actually can find the bind function in the source code.
Using this code dosen't work too:
relate on another issue #82
The text was updated successfully, but these errors were encountered: