Xpages中的Select2无法添加新值:错误是"验证错误:值无效"

时间:2016-03-07 00:25:09

标签: xpages jquery-select2-4

我在XPage中使用Select2(4.0)。我有一个ComboBox,其值与bean中的属性相关联,并且我在页面加载之前填充的viewScope变量填充了选择项(现在)。

用户可以输入新值,但是当我去保存数据时,我收到验证错误:

enter image description here

这不是我写的验证错误,而是来自Xpages。虽然我可以在保存页面时输入新值(" Apple")但它会显示此错误并删除我的新值。

我认为这与新值不在可能值列表中的事实有关,但我不确定。

我发现其他posts表示我必须在提交页面之前将新值添加到值列表中。我试过这个,但它也没有用。

我非常喜欢select2,并希望将它用于所有组合框和列表框,但有很多时候需要输入新值。

comboBox的代码:

<xp:comboBox id="model"
                                value="#{javascript:PCModel.model}" xp:key="field">
                                <xp:selectItems>
                                    <xp:this.value><![CDATA[#{javascript:viewScope.models}]]></xp:this.value>
                                </xp:selectItems>
                            </xp:comboBox>

我的脚本阻止:

<xp:scriptBlock id="scriptBlock1">
        <xp:this.value><![CDATA[$(document).ready(
function()
{
  x$("#{id:model}").select2({

  tags: true,
  createTag: function (params) {
    return {
      id: params.term,
      text: params.term,
      newOption: true
    }
  ;},

  templateResult: function (data) {
    var $result = $("<span></span>");
    $result.text(data.text);
    if (data.newOption) {
      $result.append(" <em>(new)</em>");
    }
    return $result;
  }
}
)
}
)]]></xp:this.value>
    </xp:scriptBlock>

0 个答案:

没有答案