0

I am trying to create a select element using EJS (embedded javascript) in Geddy framework. What I want to do is have something like (just an example):

<select>
  <option value="int"> Integer </option>
  <option value="float"> Single precision decimal point </option>
</select>

I don't find any examples... I know that for creating a select like

<select>
  <option value="X"> X </option>
  <option value="Y"> Y </option>
</select>

I have to write

<%- contentTag('select', ['X', 'Y']} %>

But how to obtain what I want?

UPDATE:

I've found the select_tag in the EJS documentation, but it is not recognized... I've also tried a hybrid like

<%- contentTag('select', [{value: NumberTypeEL.NonNegativeInteger, text:'nonnegative integer'}, {value: NumberTypeEL.Integer, text: 'integer'}, {value: NumberTypeEL.Decimal, text: 'decimal'}, {value:NumberTypeEL.Fraction, text:'fraction'}], {class:'span6', name:'numberType'}) %>

but still nothing. Any other ideas?

  • Not an answer, but I remember an [old issue](https://github.com/mde/geddy/issues/227) I was supposed to fix. Have a look. Also this doesn't seem to be supported, so I'll [add another issue on geddy](https://github.com/mde/geddy/issues/325). I'll try to have a look later today or tomorrow. – Miguel Madero Mar 11 '13 at 16:14
  • I had a quick look and seems like an easy fix, I just have to test it later. – Miguel Madero Mar 11 '13 at 16:16
  • The issue was closed, but it's not on NPM yet. I'll let you know once it's updated. – Miguel Madero Mar 13 '13 at 00:51
  • thanks! when you have some time, please take a look at [this](http://stackoverflow.com/questions/15064641/geddy-js-overwrites-custom-id) too... – Sorin Adrian Carbunaru Mar 13 '13 at 15:04
  • ummm...after you'll notice me, will I have to reinstall Geddy using NPM?...and you should check out the documentation for selectTag, because there your html code is not displayed, instead the result of that code is – Sorin Adrian Carbunaru Mar 13 '13 at 17:44
  • Yes, you will have to update from NPM. You could also get the latest from github (git clone git@github.com:mde/geddy.git && cd geddy && make && sudo make install) I fixed the problem with the documentation, thanks for letting me know. – Miguel Madero Mar 13 '13 at 20:49
  • so, I still have to wait a bit for having the changes with NPM? – Sorin Adrian Carbunaru Mar 13 '13 at 21:58
  • I'm guessing soon. I pushed the changes to the right place already, so just waiting as well, I'll let you know, in the meantime, get it from github, it's really simple. You might not even have to install or remove your NPM version, just run geddy/bin/cli.js for each CLI command instead of geddy and that will do. – Miguel Madero Mar 15 '13 at 01:29
  • It's updated now. Have a look and let me know how it works. – Miguel Madero Mar 15 '13 at 06:43
  • the `option` elements indeed have a `value` attribute now... but, for some reason, the generated `select` elements do not have attributes anymore (like `class` and `name`)... and this happens both for the `contentTag('select', ...)` and the `selectTag`... – Sorin Adrian Carbunaru Mar 15 '13 at 14:50
  • Ooops, it was so obvious I didn't even add a test for this case. I was missing a parameter. It's fixed on master, but not on NPM yet. – Miguel Madero Mar 15 '13 at 19:07

1 Answers1

2

On the new version there's a new selectTag. It works like the EJS example you referred to, so you can pass an array of objects. It also lets you specify a selectedOption. You can still use contentTag("select"...) and it works with the array of objects, however, with the contentTag you can't select an option.

Another way to do this that was already there is to use contentTag and pass it a string instead of an array like

contentTag('select', "<option value=\"1\" selected>Text 1</option>");

Please have a look at the documentation on geddyjs.org/documentation and look for selectTag

NOTE: the documentation updates over night, so it might not be there when you go there, I'm copying it for now.

selectTag

`selectTagString(optionsArray, selectedOption, htmlOptions)

Creates a HTML select tag using the given optionsArray to create HTML option elements.

optionsArray could be an array of strings, numbers or an object with value and text properties to be used for the value attribute and option element content respectively.

Examples:
selectTag(['geddy', 'alex', 'neil'])
// => '<select><option value="geddy">geddy</option><option value="alex">alex</option><option value="neil">neil</option></select>'

selectTag(['open', 'close'], todo.status, { class:'span6', name:'status' })
// => '<select class="span6" name="status"><option selected="selected" value="open">open</option><option value="close">close</option></select>'

selectTag([{value: 1, text: "Text 1"}, {value: 2, text: "Text 2"}], 2)
// => <select><option value="1">Text 1</option><option selected="selected" value="2">Text 2</option></select>
Community
  • 1
  • 1
Miguel Madero
  • 1,948
  • 13
  • 21