Comments (17)
The checkbox attribute value defines what will be submitted when checked,
but you will never submit the form because nothing is intended to be used within the forms.
The button sources is the list of element ids whose values will be collected when postback is triggered. The values collected by val(), by html() if the element is has data-html attributes or joined list of values if the elements has data-list attribute. Because you never change the value of the checkbox the val() will always return off in this case.
So you should define the postback for the #checkbox{} element and do something on value change.
Or change the value of the checkbox element manually prior to handle the button postback.
Something like this:
wf:wire(wf:f("$('#~s').on('click', function(e){ $(this).attr('value', 'new value'); })", [CheckboxId]));
should work (however I did not test it :) )
from n2o.
Ok, перехожу на русский (потом сотрете или переведете), что бы точно быть понятым и понять ответ. :)
Как идеологически верно с точки зрения фреймворка обрабатывать формы, включая checkbox,radiobox,select и т.д ?
Можно пример? Ни в skyline, ни еще где я пока такого не нашел.
from n2o.
Please update your checkbox_element and n2o.js and you will be able to get the checkbox state through the button source. Only checked checkboxed will have the values
from n2o.
Ok, thank you.
But still waiting for answer on my russian question about ideology of frameworks work with forms and data.
from n2o.
We are not using forms, we collecting data by javascript. So in some simple cases .val was enough, however to include all set of controls we need to include them into n2o collecting function (first function in n2o.js) or do it ourselves by wiring javascript. My point is that framework should care the simple cases, Andrew's point is that we should keep n2o.js as much clean as possible.
from n2o.
Thank you, Maxim, for quick response. I know what to do right now.
Please, do not throw your work.
from n2o.
You can use your forms with no additional support from the framework. All the parameters you submit to some server side module can be collected through the wf:qs().
from n2o.
Already checked it. :)
from n2o.
Dear doxtop@,
Your advice is not working. With wf:q(checkbox) I got declared value always.
from n2o.
We've tested and it should work, it was committed from working sample. Please clarify the problem.
For query string parameters you should use wf:qs(<<"parameter">>) binary parameters.
However this is old way of passing data to the server through HTTP.
You should use manual wiring for collecting data from custom controls to pass them through WebSockets.
Here is working sample with updated n2o.js:
#checkbox{id=islatin, name=islatin, class=["checkbox"],
checked=false, value=off, body= <<" Aaa">>},
#button{class=["btn btn-primary"], id=btn_send_one, body= <<"Send">>,
postback=send_one, source=[islatin]}.
event(send_one)-> error_logger:info_msg("Latin value: ~p", [wf:q(islatin)]);
from n2o.
Hmm. Strange. Ok.
Declare checkbox:
#checkbox{id=islatin, name=islatin, class=["checkbox"], checked=false, value=off, body= <<" ">>},
...
wf:q(islatin) always returns a value="off".
n2o_scripts, n2o was updated. I saw changes in n2o.js + checkbox_element.erl.
I can see if(this.attr('data-toggle')=='checkbox') { if ($(this).is(':checked')) return this.val(); else return 'undefined'; ...
So, I think that it must be working.
Also I inspected checkbox element in rendered page and saw:
It must be working, but...
Chrome, MacOS X.
from n2o.
Please, add some console.log in that place of JS to be sure that this code was executed in browser.
from n2o.
vim deps/n2o_scripts/n2o/n2o.js :
} else if(this.attr('data-toggle')=='checkbox') {
console.log('my checkbox checking...');
if ($(this).is(':checked')) {
console.log("it's checked");
return this.val();
}
else {
console.log("it's not checked");
return 'undefined';
}
$ javascript.sh
$ rebar compile; ./stop.sh; ./release.sh; ./start.sh
console log in browser is empty. What I forgot to do ?
from n2o.
$ release_sync.sh
from n2o.
my checkbox checking... all.min.js:1
it's not checked all.min.js:1
my checkbox checking... all.min.js:1
it's not checked all.min.js:1
my checkbox checking... all.min.js:1
it's not checked all.min.js:1
Always. When checked or not. My form has three checkboxes. I checked one, two . But always selector does not work.
from n2o.
Found! (this.is(':checked')) , not $(this).is(':checked').
my checkbox checking... all.min.js:1
it's not checked all.min.js:1
my checkbox checking... all.min.js:1
it's checked all.min.js:1
my checkbox checking... all.min.js:1
it's not checked
attach:
Submit send one message: [], [], [], "undefined", "off", "undefined", []
from n2o.
Great! Thanks for contribution.
from n2o.
Related Issues (20)
- Fire event on keypress/keydown HOT 4
- Apps couldn't be loaded: [kvs,mnesia] HOT 2
- question - Machine specs for the wrk benchmark? HOT 1
- n20 book link is broken on readme
- no function clause matching lists:flatten HOT 1
- no function clause matching lists:flatten HOT 5
- Change ws.send to wsn.send in all JS and NITRO renderers HOT 1
- bert.js int_to_bytes("true") causes node/v8 to crash
- bert.js decode error on the server: badarg HOT 1
- call to an undefined module ? HOT 1
- Автор наркоман HOT 1
- xhr.js has been deleted HOT 2
- Fails on basic setup HOT 1
- N2O to support latest Cowboy 2.x HOT 6
- Update n2o_mqtt to support EMQ X 3.x
- Adjust n2o_ring:send for IoT project
- Support TCP Connections
- n2o crash at startup: HOT 5
- from or form in record #cx ? HOT 4
- There is no samples folder inside n2o HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from n2o.