Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #addMedicamentoAutoComplete(targetId, medicamentoList) {
- let campo = null;
- const t=this, dom = document;
- if(document.querySelector(`#${targetId}`) === null) {throw 'could not get the selector of the nombre_medicamento column'};
- document.querySelector(`#${targetId}`).addEventListener("autoComplete", event => {
- campo = event.target;
- });
- new autoComplete({
- data: {
- src: medicamentoList,
- key: ['codigo_medicamento'],
- cache: false
- },
- noResults: () => {
- Notiflix.Report.Failure('Error', 'No existe Medicamento', 'Cerrar este aviso', function() {
- campo.value = '';
- });
- },
- onSelection: feedback => {
- let selectedItemList = [];
- const selection = feedback.selection.value.codigo_medicamento.split(' | ');
- $('input[name=codigo_medicamento]').each(function(k,v){
- if($(v).val()){
- selectedItemList.push($(v).val());
- }
- });
- if(selectedItemList.includes(selection[0])){
- Notiflix.Report.Failure( 'Medicamento repetido', 'Este medicamento ya existe', 'Cerrar', function(){
- campo.value="";
- campo.focus();
- });
- return;
- }
- const tbody = $('#tabla_prescripcion tbody');
- // put the values to the corresponded input values
- campo.parentElement.parentElement.children[0].children[0].value = selection[0]; // codigo_medicamento
- campo.value = selection[1]; // nombre_medicamento
- campo.parentElement.parentElement.children[2].children[0].value = selection[2]; // forma_farmaceutica
- campo.parentElement.parentElement.children[4].children[0].value = selection[3]; // concentracion
- // disable the current field and unset id
- campo.disabled = true;
- campo.id="";
- //lista automatica del autocomplete
- campo.parentElement.children[1].innerHTML="";
- campo.parentElement.children[1].id="";
- // Revisar despues, esta seccion clona los nodos del tbody sin los eventos(autocomplete, selected)
- // Pero se debe recuperar los eventos del select node
- //const clon = tbody.children().clone();
- //tbody.html(clon);
- tbody.append(empty_row_medicacion_pre_anestesica(t.#via_list));
- t.#addMedicamentoAutoComplete("crear_receta_nombre_medicamento", t.#medicamentoList);
- },
- maxResults: 20,
- selector: `#${targetId}`,
- threshold: 1,
- debounce: 300,
- searchEngine: "strict",
- highlight: true,
- resultsList: {
- render: true,
- container: source => {
- source.setAttribute("id", "autoComplete_list");
- },
- destination: document.querySelector(`#${targetId}`),
- position: "afterend",
- element: "ul"
- },
- resultItem: {
- content: (data, source) => {
- source.innerHTML = data.match;
- },
- element: "li"
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement