javascript - Entering values into a jquery-select2 that are not in the select list -


i have use case allow people type values text box of select2 plugin not appear in select list.

in 1 case providing validation , not submit unless user has valid item selected until do not want clear values. select box might contain 1.00, 1.50, 1.75, na, abs , user has typed 1.80. invalid value don't want lose changes, flag box invalid , allow them fix changes. not want add 1.80 select box invalid value, don't want clear either.

how possible achieve this?

if you're validating in js, select2 has example dynamic loading/generating data overrides query() repeats user's input.

see: http://ivaynberg.github.io/select2/ 'loading data'

i solved similar problem (server-side) jquery ui 'autocomplete'. here, took approach of returning objects wrapping both label possible explanatory message, text value without decoration, , combined id value & status flag. overrode select store text & id hidden fields.

in case, distinguishing between existing customers reference, or creating new customer entered name. able list options of matching existing customers or creating "abc new customer", quite nicely:

user enters: "alphabet soup" , sees choice of:

  • alpha packaging
  • campbells soup
  • create "alphabet soup"

a similar technique might applicable you. hope helps.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -