getValue not working on custom template

2019-09-03 07:26发布

问题:

I've been able to make my own field, using a costum template. This field consist in a textField followed by button at the end, on the same line, but I'm confronted to an issue.

When I'm using form.getValue(), it does return the original values, I mean, if I modify 1 field and then do a getValue(), the modification won't be visible and I will still get the value I had when loading the form.

I'm pretty sure there is a problem with my template but I can't figure what to do ! :(

Here is my templates code :

{% raw %}
<script type="text/x-handlebars-template" id="input-group-addon-template">
    <div class="input-group">
    <input type="{{inputType}}" value="{{data}}" id="{{id}}" {{#if options.placeholder}}placeholder="{{options.placeholder}}"{{/if}} {{#if options.size}}size="{{options.size}}"{{/if}} {{#if options.readonly}}readonly="readonly"{{/if}} {{#if name}}name="{{name}}"{{/if}} {{#each options.data}}data-{{@key}}="{{this}}"{{/each}} {{#each options.attributes}}{{@key}}="{{this}}"{{/each}}/>
        <div class="input-group-btn" id="{{id}}-basic-btn"> 
        <button class="btn btn-default" id="{{id}}-button" onclick="test(event)" >
            <i {{#if options.readonly}}class="fa fa-lock"{{else}}class="fa fa-unlock"{{/if}}></i> 
        </button>
       </div>
   </div>
</script>
{% endraw %}
<script> 

回答1:

With some help, I've been able to get it to work. So I just had to modify the template, new template :

<script type="text/x-handlebars-template" id="input-group-addon-template">
    <div class="input-group">
        {{#control}}{{/control}}
        <div class="input-group-btn" id="{{id}}-basic-btn" > 
            <button class="btn btn-default" id="{{id}}-button" onclick="click_function(event)" >
                <i {{#if options.readonly}}class="fa fa-lock"{{else}}class="fa fa-unlock"{{/if}}></i> 
            </button>
        </div>
    </div>
</script>

So the big difference is that we don't precise the "input-type" anymore so that we don't override all usefull function as getValue etc.

Feel free to add some explication ! :D