Sign In Register

How can we help you today?

Start a new topic
Answered

Dynamic Form dropdown

I'm creating a dynamic form to create characters for my game so I have a list and I can edit each item etc but in the edit modal popup I would like to display a dropdown menu of character classes coming from property sets so I was wondering how I can do this?.. I thought I could do it using gs-query but I only need the drop menu not the other options.


Best Answer

I just solved this myself so I'm posting it here just in case anyone else have the same question:


This is the javascript:

var classes = [];
        var classProp = Spark.getProperties().getProperty("characterClasses");
        for (i = 0; i < classProp.data.length; i++) {
            var cl = classProp.data[i];
            classes.push({name: cl, selected: cl == form.class});
        }
        form.characterClasses = classes;

 And this is the html code:  

<label class="control-label" for="description">Class</label>
    <select name="characterClass" class="input-block-level" has-validation="true" required aria-invalid="false">
                    {{#each character.characterClasses}}
                        <option value="{{name}}" {{#compare selected "==" true}}selected=""{{/compare}}>{{name}}</option>
                    {{/each}}
   </select>

  

1 Comment

Answer

I just solved this myself so I'm posting it here just in case anyone else have the same question:


This is the javascript:

var classes = [];
        var classProp = Spark.getProperties().getProperty("characterClasses");
        for (i = 0; i < classProp.data.length; i++) {
            var cl = classProp.data[i];
            classes.push({name: cl, selected: cl == form.class});
        }
        form.characterClasses = classes;

 And this is the html code:  

<label class="control-label" for="description">Class</label>
    <select name="characterClass" class="input-block-level" has-validation="true" required aria-invalid="false">
                    {{#each character.characterClasses}}
                        <option value="{{name}}" {{#compare selected "==" true}}selected=""{{/compare}}>{{name}}</option>
                    {{/each}}
   </select>

  

Login to post a comment