Skip to content
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

obj('me') does not reference the "target" of an #event #103

Open
7stud opened this issue Jul 31, 2018 · 0 comments
Open

obj('me') does not reference the "target" of an #event #103

7stud opened this issue Jul 31, 2018 · 0 comments

Comments

@7stud
Copy link

7stud commented Jul 31, 2018

BuildInfo.txt:

Nitrogen Version:
2.3.1

Built On (uname -v):
Darwin Kernel Version 11.2.0: Tue Aug  9 20:54:00 PDT 2011; root:xnu-1699.24.8~1/RELEASE_X86_64

According to the docs:

Event Action - #event {}
...
...
If the 'actions' attribute is set (inherited from action base), then these actions will be run when this event is triggered. This attributed can be set to a list of actions, a single action, or an Erlang string, which will be run as Javascript.

Within the Javascript, you can use obj('id') where id is the id of a Nitrogen element. You can also use obj('me') to refer to the target of the current action.

If I use obj('mytextbox').value, the following code successfully alert's the value of a textbox:

%% -*- mode: nitrogen -*-
%% vim: ts=4 sw=4 et
-module (my_page).
-compile(export_all).
-include_lib("nitrogen_core/include/wf.hrl").
-include("records.hrl").

main() -> #template { file="./site/templates/bare.html" }.

title() -> "Hello from my_page.erl!".

body() -> 
    wf:wire(#event{
        type=click,
        trigger=mybutton,
        actions="alert( obj('mytextbox').value )"
    }),
    #panel{ style="margin: 50px;", body=[
        #h1{ text = "My Simple App..." },
        #label{ id=mylabel, text="Enter your name:"},
        #textbox{ id=mytextbox },
        #button{ text="Submit", id=mybutton}
    ]}.

However, according to the quote I posted above from the docs, I should also be able to set target=mytextbox and then use obj('me') in place of obj('mytextbox') in the js, but the alert does not popup when I try that:

%% -*- mode: nitrogen -*-
%% vim: ts=4 sw=4 et
-module (my_page).
-compile(export_all).
-include_lib("nitrogen_core/include/wf.hrl").
-include("records.hrl").

main() -> #template { file="./site/templates/bare.html" }.

title() -> "Hello from my_page.erl!".

body() -> 
    wf:wire(#event{
        type=click,
        trigger=mybutton,
        target=mytextbox,
        actions="alert( obj('me').value )"
    }),
    #panel{ style="margin: 50px;", body=[
        #h1{ text = "My Simple App..." },
        #label{ id=mylabel, text="Enter your name:"},
        #textbox{ id=mytextbox },
        #button{ text="Submit", id=mybutton}
    ]}.


My javascript console shows the following error:

[Error] Error: Syntax error, unrecognized expression: [object HTMLDocument]
	error (jquery.js:2:12775)
	tokenize (jquery.js:2:18605)
	select (jquery.js:2:21323)
	fb (jquery.js:2:7354)
	find (jquery.js:2:23600)
	init (jquery.js:2:24171)
	m (jquery.js:2:407)
	objs (nitrogen.min.js:1:15379)
	obj (nitrogen.min.js:1:14499)
	anonymous (page:23)
	dispatch (jquery.js:3:8442)
	handle (jquery.js:3:5145)

I don't see any errors in the nitrogen shell. I tried the code in Safari, Chrome, and Firefox.

Finally, when I look at the html source, I notice that the id attribute is not set for the button or the textbox:

<input type="text" class="wfid_temp879098 wfid_mytextbox textbox" value="" />
<input type="button" value="Submit" class="wfid_temp879125 wfid_mybutton button" />

Instead, a class is added to the class attribute, e.g. wfid_mytextbox. Why is that? I think at the very least the Base Element docs should mention that the id field does not actually set the id attribute of the html element. It's really confusing for a nitrogen beginner to set the id field of an element, then write some js, e.g. document.getElementById('theId'), and not be able to access the element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant