Dynamic Input with JQuery

1

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

  • It should be an input.

  • As I type, it already fetches information previously entered into the system.

  • If you did not find it, this field will be inserted.

  • Most importantly, you can only allow a single data entry.

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

    In addition, I need to block so that it is possible to insert only 1 field per <input>

        
    asked by anonymous 23.03.2017 / 17:59

    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
    });
    
        
    23.03.2017 / 18:34