Dynamic Input with Jquery

Asked

Viewed 89 times

1

I need to insert into a system a <input> having the following characteristics:

  1. Must be an input.

  2. As I type, it already searches information previously entered in the system.

  3. If not found, this field will be inserted.

  4. Must allow insertion of "space", since this field is for inserting names of people.

  5. Most important: you can only insert a single piece of data.

I’ve already found a similar solution with Select2, but the function that allows inserting a field when it is not previously located does not allow inserting spaces (similar to the TAGS field here in Stack Overflow)

Also, I need to lock so that it is possible to insert only 1 field per <input>

  • What code do you have so far?

  • I’m wearing a <input class="select2-ubi">, with the following jquery: $(".select2-ubi").select2({&#xA; tags: true,&#xA; maximumSelectionLength: 1&#xA;}); However, it does not bring the results for me to select... It appears as follows: You can only select 1 item

  • Edit your question and put HTML and JS in the code

  • You can also do this with angular (autocomplete)

1 answer

0

HTML:

<select class="form-control demo-select2-3" name="pro_add_colaborador_3">
    <option value="">Selecione</option>
    <?php
        $search_contributors = $pdo->query("SELECT con_id, con_nome_completo 
                                            FROM contributors 
                                            WHERE con_cod_cliente IN($accounts_src)
                                            ORDER BY con_nome_completo"); 
        $search_contributors->execute();
        while($res_contributors= $search_contributors->fetch(PDO::FETCH_ASSOC)){
    ?>
    <option value="<?php echo $res_contributors['con_id']; ?>"><?php echo $res_contributors['con_nome_completo']; ?></option>
    <?php } ?>
</select>

JQUERY

$(".select2-ubi").select2({
    tags: true,
    maximumSelectionLength: 1
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.