jeudi 19 février 2015

How bind select options in the HTML with two pre-defined values to insert data in mongodb

I create an event creator in my admin dashboard, and everything is working ok, but now i need insert a new field:



infoType: Object


In my HTML event creator, i have this selection:



<label for="infoType">Information Type:</label>
<select id="infoType" name="infoType">
<option>Normal</option>
<option>Special</option>
</select>


With a post to /event/create


When this event arrive in my controller, i need save all the form inputs in my database, and is fine, this part is 100% working.


But, before make the save, i am using this code to bind the select option with the real value of the field infoType in the database:



event.pre('save', function(next) {
if (this.infoType === 'Normal') {
this.infoType = [
['Normal text.'],
['Normal text continuation.']
['Normal text continuation']
]
} else if (this.infoType === 'Special') {
this.infoType = [
['Special text.'],
['Special text continuation.'],
['Special text continuation.']
]
}
});


I want know if this is right, is working, but for me looks wrong.


I CANT change the way that i am using to insert text, i need separate the texts in arrays, because i am using a for loop to show this texts in an unordered list, and i don't know other way to make the code looks like this:



<ul>
<li>ARRAY 1</li>
<li>ARRAY 2</li>
<li>ARRAY 3</li>
</ul>

Aucun commentaire:

Enregistrer un commentaire