vendredi 19 juillet 2019

How to send the values of checked items in a dynamic list from a database displayed in a view to controller?

How to send the values of checked items in a dynamic list from a database displayed in a view to controller ?




jeudi 18 juillet 2019

Get value checkbox with the same class

I need to get values from checkboxes with the same class and different values, to get these values when activate submit bottom and select the different checkbox

<script>
  jQuery(.simple_search).click(function(){
    if (jQuery('.skey_send').is(":checked")){
     var s_key=jQuery(".skey_send").val();
     alert("Value is : "+s_key);
    } 
  });
</script>


<input type="submit" class="simple_search" name="send_s" value="GO" />

<input type="radio" name="s_key" class="skey_send" value="all" />All
<input type="radio" name="s_key" class="skey_send" value="card" />Card
<input type="radio" name="s_key" class="skey_send" value="phone" />Phone
<input type="radio" name="s_key" class="skey_send" value="price" />Price

The Problem´s always I get value from the first checkbox but no when clicking over another or different checkbox

I need to know what I need implement or add in my code for getting value from different checkboxes with the same class when checking




How to clear textboxes nested inside a tabControl, tabPage and 2 panels?

The picture below represents a plugIn I am building.

Yellow = tabControl1; Orange = tabPage1; Blue = Main Panel (mainPanel); Green = 3 different panels inside the main panel (panel1, panel2 and panel3); White = TextBoxes (that I want to clear); DarkBlue = CheckBoxes corresponsing to the green panels

plugIn

I am trying to clear any text from the text boxes if they have text in them and clear the checkboxes if they are checked with a button click.

I researched online and tried to accomplish this by the following way but it doesn't seem to be the correct way to handle this problem.

foreach (Control a in tabControl1.Controls)
            {
                foreach(Control b in tabPage1.Controls)
                {
                    foreach (Control c in mainPanel.Controls)
                    {
                        foreach (Control d in panel1.Controls)
                        {
                            if (d is TextBox)
                            {
                                d.Text = " ";
                            }
                            if (d is CheckBox)
                            {
                                ((CheckBox)d).Checked = false; 
                            }
                        }
                    }
                }
            }

I have only shown panel1 here but tried doing the same thing for panel 2 and 3 as well.

What exactly am I doing wrong here? Any help would be greatly appreciated!




setOnItemClickListener cannot modifie template's checkbox

I'm working on a program in which I need to check some items. For that, I created a listView, an adapter and a template (XML of the adapter). The template contains text and a checkbox then in my activity I can see each item with it's name and the checkbox. I have to manage the number of items checked and then I tried to do this with setOnItemClickListener, but it doesn't works...

I looked around the web, but nobody got this problem, then I think that I'm doing it the wrong way, or nobody needed it ?

Here's my setOnItemClickListener :

m_listViewConcepts.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                CheckBox checkBox = view.findViewById(R.id.checkbox_pick_concepts);
                if (!checkBox.isChecked() && m_conceptCount < m_maxFrames) {
                    checkBox.setChecked(true);
                    m_conceptCount++;
                    m_textViewConceptsCount.setText(String.format(getResources().getString(R.string.concept_count), m_conceptCount, m_maxFrames));
                } else {
                    checkBox.setChecked(false);
                    m_conceptCount--;
                    m_textViewConceptsCount.setText(String.format(getResources().getString(R.string.concept_count), m_conceptCount, m_maxFrames));
                }
            }
        });

It doesn't even can be clicked... If you have a lead or something it could help me a lot !




Get all checkboxes and check them by previous sibling

I have a code like this:

<div class="elements" id="elements">
    <span>
        <span>Check anyone (required)</span>
    </span>
    <input type="checkbox" name="vehicle" value="minivan"> Minivan
    <input type="checkbox" name="vehicle" value="car"> Car
    <input type="checkbox" name="vehicle" value="boat"> Boat

    <span>
        <span>Check anyone</span>
    </span>
    <input type="checkbox" name="sport" value="basketball"> Basketball
    <input type="checkbox" name="sport" value="soccer"> Soccer
    <input type="checkbox" name="sport" value="tennis"> Tennis
</div>

<button id="check">Check</button>

<script>
    document.getElementById("check").onclick = function () {
        // Check it all... if required text is found and at least one checkbox is not found for that specific checkbox name, then throw alert
    }
</script>

I want to check all checkboxes in the div class/id elements and then check the previous span span tag and if there is a "required" text, then make sure one at least one checkbox is selected.

For example, let's start with checkbox name="vehicle". We reference/look back in the previous sibling <span><span> and we see if the text "required" exists. If it does exist, we need to make sure at least checkbox of name=vehicle is checked. If not, we need to `alert('error! please check a checkbox');

For example in name="sport", we do not have to check if at least one checkbox is checked because the text "required" does not exist in previous span span.

I know its weird but it has to be like this - just need to work with it. any help? thanks everyone!




If Checkbox is Checked Keep DIV hidden even on page reload

I have a rails form. When a checkbox is selected (true in database) I want to keep the div hidden. I found other solutions but on page reload it reappears, I'd like to keep the div hidden if checked or true.

  <div class="form-group">
    <%= form.check_box :tos_checkbox, class: "terms_of_services" %>
    <%= form.label :tos_checkbox, "Agree to TOS" %>
  </div>

  <div id="hide_if_above_checked">
    Do You Agree to Our TOS
  </div>

I know this script will not work, but been attempting several different examples to solve my problem.

  $(function () {
      $('.terms_of_services').change(function () {
          if(checkbox.checked == true){
              document.getElementById("hide_if_above_checked").setAttribute("d-none");
          }else{
              document.getElementById("hide_if_above_checked").removeAttribute("d-none");
          }
      });
  });




mercredi 17 juillet 2019

Checkbox return value

my checkbox is working fine and I get the return true / false correctly, however true or false is displayed on a table, I want to replace this return with a text if true by "valid" if false by "error"

thank you