我正在使用ui-select中的選擇框。所有工作正常,但我想允許手動輸入的文本,並不想限制用戶從列表中可用的值。如果我輸入文本,它會正確過濾我的列表。但是,當我沒有點擊一個元素,並進入下一個領域,我的文字將被丟棄。允許在ui-select中手動輸入文本
任何想法?
感謝和問候, 亞歷
我不想顯示我的代碼,因爲我認爲這是不正確的,但它要求:
<ui-select ng-model="formData[field.id].selected" theme="bootstrap">
<ui-select-match placeholder="{{ lists[field.id].placeholder }}">{{$select.selected.text}}</ui-select-match>
<ui-select-choices repeat="item in lists[field.id].list | filter: $select.search">
<div ng-bind-html="item.text | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
的數據存儲在formData[field.id].selected
。 field.id
是要顯示的當前字段的編號(我正在動態生成我的表單)。假設它存儲一個唯一的int值。
編輯2015年4月8日 我的解決辦法: 我發現它好像沒有相當於C#組合框。所以我繼續使用兩個獨立的領域。這不是我想要的東西,但它現在適用於:
<ui-select ng-model="formData[field.id].selected" theme="bootstrap">
<ui-select-match placeholder="{{ lists[field.id].placeholder }}">{{$select.selected.text}}</ui-select-match>
<ui-select-choices repeat="item in lists[field.id].list | filter: $select.search">
<div ng-bind-html="item.text | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
<?php echo __('Create a new element if value is not in list'); ?>
<div class="input-group">
<span class="input-group-addon">
<input type="checkbox" ng-model="disabled[field.id]">
</span>
<input type="text" value="" ng-disabled="!disabled[field.id]" class="form-control" ng-model="formData[field.id].newValue" />
</div>
嗯,我不知道爲什麼我被低估了。如果有人能指點我一些文檔就足夠了。 ui-select github提供了一些示例,但沒有可編輯的文本。 – AlexWerz
你能分享一些代碼嗎? – nalinc
我不想分享代碼,因爲我很確定它不正確。如果有幫助,我會添加一些。 – AlexWerz