Mark a checkbox when I select a value in select


david medina

I'm working with a JSON file where I put values ​​in a select multiple and when I select a value in the select I am trying to mark a checkbox but I don't know how I can do it

Here is my JSON file

 "tipocasa": [
        {"tipo":"Propia" , "tipo_casa":1},
        {"tipo":"Rentada" , "tipo_casa":2},
        {"tipo":"Otro" , "tipo_casa":3}
    ]

This is the selection code I use for ui-select

          <ui-select multiple ng-model="entrevistainicialModel.idcomportamiento"
                           ng-disabled="false"
                           search-enabled="true"
                           append-to-body="true"
                           class="form-control ">
                    <ui-select-match placeholder="Comportamientos">
                        {{$item.comportamiento}}
                    </ui-select-match>
                    <ui-select-choices repeat="multipleItem.idcomportamiento as multipleItem in datosJson[0].comportamientos | filter: $select.search">
                        {{multipleItem.comportamiento}}
                    </ui-select-choices>
                </ui-select>

Here is the checkbox code

         <label class="checkbox-inline custom-checkbox nowrap">
            <input align="center" type="checkbox" ng-model="entrevistainicialModel.idcomportamiento" value="1">
                            <span align="center">Propia</span>
                        </label>

             <label class="checkbox-inline custom-checkbox nowrap">
            <input align="center" type="checkbox" ng-model="entrevistainicialModel.idcomportamiento" value="1">
                            <span align="center">rentada</span>
                        </label>

         <label class="checkbox-inline custom-checkbox nowrap">
            <input align="center" type="checkbox" ng-model="entrevistainicialModel.idcomportamiento" value="1">
                            <span align="center">Otro</span>
                        </label>

Any ideas or suggestions?

Jesus Carrasco

Models need to be added on-removeand on-selectchanged first. and assign. Add to each checkbox according to your needs.

I made an example based on your data.

HTML

    <ui-select multiple ng-model="data.selected" on-remove="$item.selected=false" on-select="$item.selected = true" theme="bootstrap" sortable="true" close-on-select="false" style="width: 800px;">
    <ui-select-match placeholder="Comportamientos...">{{$item.name}}</ui-select-match>
    <ui-select-choices repeat="comportamiento in datosJson.comportamientos">
  {{comportamiento.name}}
    </ui-select-choices>
  </ui-select>              
  <p>Selected: {{data.selected}}</p>

  <div ng-repeat="item in datosJson.comportamientos">
    <input type="checkbox" ng-model="item.selected">{{item.name}}
    <br>
  </div>

controller

$scope.datosJson = {
comportamientos:
  [
    {id:1, name:'comportamiento1'},
    {id:2, name:'comportamiento2'},
    {id:3, name:'comportamiento3'}
  ]
  };

This is plnkr with DEMO just change your data.

Related


Disable checkbox when I select

1993 I have problem in html and javascript. I have tried different methods but nothing worked. Here is my sample code. <select id = "testselect" name = "testselect"> <option> </option> <option id = "o1" name = "testselect" value = "1" onse

Select value of checkbox JTable when button is clicked

Akilesh Mohale I have a JTable where the last column is Checkbox(multiple select). I want to get the value of the row selected on a specific button click. Only the value that needs to be checked. Any thoughts on this? Object[] columnNamesTest = {"Request No","

jQuery select option value checkbox

Kent Bjerg Budolfsen I'm running into a problem and I hope someone can help me solve it. I have a search form with some dropdown menus (A, B and C) Need to uncheck a checkbox when I select option value BI I've tried all the solutions I've found online and can'

xpages checkbox single value select

Florin M. Is it possible for the user to select only one value from one <xp:checkBoxGroup>? In other words, can a checkBoxGroup work like a radioButton? I know I can easily change the control to a radioButton, but I'm just curious. poison youth You can use the

Select checkbox based on database value

Jay I need some help! , I'm working on a project where I want all these checkboxes to be checked which have a value fetched from a database. Suppose I have a table with 4 fields which are id, news_title, news_desc and flag. The flags field has values such as 0

jQuery select option value checkbox

Kent Bjerg Budolfsen I'm running into a problem and I hope someone can help me solve it. I have a search form with some dropdown menus (A, B and C) Need to uncheck a checkbox when I select option value BI I've tried all the solutions I've found online and can'

Select checkbox based on database value

Jay I need some help! , I'm working on a project where I want all these checkboxes to be checked which have a value fetched from a database. Suppose I have a table with 4 fields which are id, news_title, news_desc and flag. The flags field has values such as 0

jQuery select option value checkbox

Kent Bjerg Budolfsen I'm running into a problem and I hope someone can help me solve it. I have a search form with some dropdown menus (A, B and C) Need to uncheck a checkbox when I select option value BI I've tried all the solutions I've found online and can'

I need to convert this select to checkbox

username I'm struggling with this, I have to change the select form for the checkbox form I can change the visual but the checkbox doesn't work like a select this is the choice <div className="form-group"> <label forhtml="road-typeControlSelect">Flags</label>

I need to convert this select to checkbox

username I'm struggling with this, I have to change the select form for the checkbox form I can change the visual but the checkbox doesn't work like a select this is the choice <div className="form-group"> <label forhtml="road-typeControlSelect">Flags</label>

If value is found, select row and mark column

flexible I need help creating a query Current situation: The output table contains IDs and levels. Each Id can appear multiple times. question: Now I want to know if the id appears at level 1, and if so, I want to mark it as number 1. If the Id has only level

select a checkbox

Gabriel I have a piece of code that only works when there are many checkboxes. However, when I have only one checkbox, the code goes wrong. Basically, what I want the macro to do is select the ckeckbox as an object and align it to a cell, which should also wor

select value when summing

Sachin Keynes I have a table with date and integer values. I want to sort the table by date and select the first n rows until the integer values sum to 12 or more. Gordon Linoff You can use cumulative sum: select t.* from (select t.*, sum(val) over (order by d

select value when summing

Sachin Keynes I have a table with date and integer values. I want to sort the table by date and select the first n rows until the integer values sum to 12 or more. Gordon Linoff You can use cumulative sum: select t.* from (select t.*, sum(val) over (order by d

Select value of checkbox group using jQuery

Dragon mantank: I'm using Zend_Form to output a set of checkboxes: <label style="white-space: nowrap;"><input type="checkbox" name="user_group[]" id="user_group-20" value="20">This Group</label> In a normal HTTP Post, the values are passed as an array, but wh

Change value of select option based on checkbox

Pratyush Pranjal Whether the value of the selected option can be changed if the user checks the checkbox. If the user selects "four" from the selection options, its default value is "4". Now, if the user checks the checkbox, the select option value is "44". <s

Select value of checkbox group using jQuery

Dragon mantank: I'm using Zend_Form to output a set of checkboxes: <label style="white-space: nowrap;"><input type="checkbox" name="user_group[]" id="user_group-20" value="20">This Group</label> In a normal HTTP Post, the values are passed as an array, but wh

Select checkbox -> click button -> update table value

username The initial value under the reattempt column will be blank. Once we select the checkbox for some row and click the button reattempt , I want to update the value column reattemptto reattempt . html <button id="reattempt">reattempt</button> <tr> <

select html checkbox based on json array value

code I have a form in which I am sending multiple checkbox items to a controller as an array, <?php foreach($groupsArray as $group) { ?> <label> <input type="checkbox" class="icheck" name="groups[]" id="groups" value="<?php echo $group["id"];?>"> <