eZ Community » Forums » Setup & design » attribute interact with javascript
expandshrink

attribute interact with javascript

attribute interact with javascript

Monday 21 November 2011 12:24:17 am - 4 replies

 

Hi,

I am trying to read an email field attribute from a class with a function in javascript. How ca I call the attribute name.

In a template I can call the attribute with the attribute_view_gui function but I cannot define the name or id of the element to call him in the javascript.

thank you for your help.

Regards.

Monday 21 November 2011 1:02:36 am

This seems like a weird problem. I don't know what you're trying to accomplish exactly, so here's some generic options to consider;

a) You don't actually use the email in JS, but post with or without AJAX while referring to the contentobject_id the email address is an attribute of, and let the backend (if any) read your email address field and send the email or whatever you are trying to accomplish
b) You make the email address available in the DOM somewhere, in a <script> tag or a data-attribute on some element for instance, and read it with JavaScript. If your problem is that the output of the attribute_view_gui isn't exactly like you need it to be, you need to read up on template override conditions or just output the value directly using $node.data_map.email_attr.content (.output.output_text). You can use the |attribute(show) template operator to find exactly where in the object structure the email address is stored.

I would go for option a – this way you don't make the email address available for spam bots and curious people sniffing around your source code, if that is a concern.

Monday 21 November 2011 1:49:38 am

 

Thank you for your help. I already manage to do what I want. I found the attribute names I need with firebug. Not the most elegant way but it is an effective one.

 

Regards.

Monday 21 November 2011 5:21:53 am

This suggestion will probably not be useful, specially since you already implemented another method, but have you considered using jquery to identify your data? I often attach phony classes to my html tags, with no css defined, only to be able to query them through jquery...

Monday 21 November 2011 9:24:20 am

For everybody interested: I am developing some "execute template code in javascript" thing that could prove a useful debugging tool. For now, you can start using ezdebug_template_operators with its ajax capabilities...

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu