doubts with select and angular Js

Asked

Viewed 66 times

1

I’m using the selectize and Angularjs, my selectize is configured like this:

in the controller

//configurando o select mrdicamento
$scope.selectize_medicamento = {
    plugins: {
        'remove_button': {
            label: ''
        }
    },
    maxItems: 1,
    valueField: 't0051_id_medicamento',
    labelField: 't0051_nome',
    searchField: 't0051_alldata',
    placeholder: "Medicamanto",
    create: false,

};
$scope.objMedicamento = { "selectedMedicamento ": null };
$scope.selectedMedicamento = [];
$scope.itemsMedicamento = [];

in the view

<div class="uk-width-medium-1-1">
   <label>Fornecedor</label>
     <selectize id="selectize_medicamento" required config="selectize_mediacmento" options="itemsMedicamento" position="bottom" ng-model="objMedicamento.selectedMedicamento"></selectize>

to get the valueField:

 var id_med = $scope.objMedicamento.selectedMedicamento;

however I need to get also the labelFiel, ie the text that is in the seclect, but I could not find out how, how could make it?

I tried already:

 var xx = document.getElementById('selectize_fornecedor').value;

but it doesn’t work

  • is supplier or drug ? because your JS is written medicine and its html is supplier. But what will make you pick the correct value is your ng-model, which in your case is: $Scope.objFornecedor.selectedFornecedor;

  • in this case ai Hugo, he picks up the id, but I need to get the text that appears in the box

  • Dude, in this selectize you’re gonna have to go rogue... I couldn’t think of any other way to help you out than this. Within your options(itemsMedication) you place an onChange like this: onChange:Function(v){Alert(Document.querySelectorAll('[data-value='+v+']')[0]. outerText);}

1 answer

0

Assuming that your HTML structure is this, you can get the text from a previous node using previousElementSibling.

Example:

var label = document.getElementById("selectize_fornecedor").previousElementSibling;
console.log(label.innerHTML);
<div class="uk-width-medium-1-1">
  <label>Fornecedor</label>
  <selectize  id="selectize_fornecedor"></selectize >
</div>

  • but in that case, it’s taking the label text right, I want to get the text q was selected in select

  • yes, are all options

Browser other questions tagged

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