Giter Club home page Giter Club logo

Comments (17)

doxtop avatar doxtop commented on May 22, 2024

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.

radetsky avatar radetsky commented on May 22, 2024

Ok, перехожу на русский (потом сотрете или переведете), что бы точно быть понятым и понять ответ. :)
Как идеологически верно с точки зрения фреймворка обрабатывать формы, включая checkbox,radiobox,select и т.д ?
Можно пример? Ни в skyline, ни еще где я пока такого не нашел.

from n2o.

doxtop avatar doxtop commented on May 22, 2024

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.

radetsky avatar radetsky commented on May 22, 2024

Ok, thank you.
But still waiting for answer on my russian question about ideology of frameworks work with forms and data.

from n2o.

5HT avatar 5HT commented on May 22, 2024

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.

radetsky avatar radetsky commented on May 22, 2024

Thank you, Maxim, for quick response. I know what to do right now.
Please, do not throw your work.

from n2o.

doxtop avatar doxtop commented on May 22, 2024

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.

radetsky avatar radetsky commented on May 22, 2024

Already checked it. :)

from n2o.

radetsky avatar radetsky commented on May 22, 2024

Dear doxtop@,

Your advice is not working. With wf:q(checkbox) I got declared value always.

from n2o.

5HT avatar 5HT commented on May 22, 2024

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.

radetsky avatar radetsky commented on May 22, 2024

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.

5HT avatar 5HT commented on May 22, 2024

Please, add some console.log in that place of JS to be sure that this code was executed in browser.

from n2o.

radetsky avatar radetsky commented on May 22, 2024

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.

5HT avatar 5HT commented on May 22, 2024

$ release_sync.sh

from n2o.

radetsky avatar radetsky commented on May 22, 2024

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.

radetsky avatar radetsky commented on May 22, 2024

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.

5HT avatar 5HT commented on May 22, 2024

Great! Thanks for contribution.

from n2o.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.