totaljs / framework

Node.js framework
http://www.totaljs.com
Other
4.36k stars 450 forks source link

Custom attributes in options View Engine #687

Closed fgnm closed 5 years ago

fgnm commented 5 years ago

I'm using that https://github.com/totaljs/framework/blob/493525b08d253b1f54a861ad3b3d4990c63a3ea2/index.js#L11801 function in html code to generate an options list and auto bind it with controller:

        <select name="gender" required>
            @{options([{name : '@(Gender)', value : '-'}, {name : '@(Male)', value : 'M'}, {name : '@(Female)', value : 'F'}, {name : '@(Other)', value : 'Other'}], model.gender)}
        </select>

Controller:

self.view("edit_user", { gender : 'F' });

It works well, but I need to set the first option (Gender = -) disabled. Reading the code I don't find a way to do that because $options does not accept custom attributes. Can you add this feature? Or maybe an helper function to create the whole <select> tag.

Thank you

petersirka commented 5 years ago

Sorry, I forgot to answer. I have updated @{options()}, you can use disabled key:

<select name="gender" required>
    @{options([{name : '@(Gender)', value : '-', disabled: true }, {name : '@(Male)', value : 'M'}, {name : '@(Female)', value : 'F'}, {name : '@(Other)', value : 'Other'}]
</select>

Just install $ npm install total.js@beta (it's stable).