简体   繁体   English

getValue在自定义模板上不起作用

[英]getValue not working on custom template

I've been able to make my own field, using a costum template. 我已经可以使用Costum模板制作自己的字段。 This field consist in a textField followed by button at the end, on the same line, but I'm confronted to an issue. 该字段包含在textField中,并在同一行的最后是按钮,但我遇到了一个问题。

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. 当我使用form.getValue()时,它确实会返回原始值,我的意思是,如果我修改1字段然后执行getValue(),则该修改将不可见,并且我仍将获得我拥有的值加载表单时。

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> 

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. 因此,最大的区别是我们不再精确化“输入类型”,因此我们不会覆盖所有有用的函数,如getValue等。

Feel free to add some explication ! 随时添加一些说明! :D :D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM