lundi 28 août 2017

Multiple Select Checkboxes

My app has two primary user roles:

Staff are university employees who fill out Referral Requests with patient details to be sent to Clinicians

Clinicians are private physicians who receive the referral request if they match the criteria detailed by the Staff user.

A Referral Request is basically a form where the Staff details the patient and their needs.

As part of this form, I want to collect information about a patient's gender identity.

I've created a model called Gender and associated genders table and then filled it in with data using seeds.

["Female", "Male", "Non-binary", "Queer", "Transgender", "Not Specified"].each do |g|

Gender.create!(name: g,
                  created_at: Time.zone.now,
                  updated_at: Time.zone.now)

I originally built the form input for gender this way, with patient_gender_id being an integer column in the referral_requests table and genders displayed as a dropdown.

  Patient's Gender Identification
    <%= collection_select( :referral_request, :patient_gender_id, Gender.all, :id, :name, prompt: true) %>

I want to change this to allow the user to select multiple gender options rather than a single one and to use checkboxes instead of a dropdown.

I know I'll need to change my controller among other things, but I keep getting errors when I try:

def referral_request_params
    params.require(:referral_request).permit(:content, :patient_gender_id, 
        :preferred_gender_id, concern_ids: [], insurance_ids: [])

end

I used this migration to try to change the patient_gender_id field to an array of integers, but I'm not sure it worked b/c I don't see anything in my schema file that would indicate that the field is now an array.

  def change
     change_column :referral_requests, :patient_gender_id, :integer, array: true, default: []
  end
end

-How do I change the form, the controller, and if necessary, the schema to accommodate multiple gender selections with checkboxes?

Any help would be greatly appreciated!




Struts- About saving checkboxes when following a link

I'm working on a jsp containing some checkboxes. My jsp is linked to a form (called SuiviTransfertForm), and this form has an attribute called checkboxUID, which is an array containing the ids of my checked checkboxes.

private String[] checkboxUID = {};

This attribute is mapped with the checkboxes of my jsp like this :

<html-el:multibox name="suiviTransfertForm" property="checkboxUID"/>

I would like to follow a link on this jsp and get the content of checkboxUID when I'm on the next page.

On the next page, I'm getting back my form like this :

SuiviTransfertForm suiviTransfertForm = (SuiviTransfertForm) form;

The problem is that checkboxUID is correctly filled if I stay on the same page, but always empty when I'm changing page. I can't find a way to achieve this.

Many thanks for your help !




Checkbox causes incorrect height on parent element

I am trying so solve a problem that causes me and my colleagues a splitting headache. Even though we've been provided a painkiller each we continue to be baffled by the way Google Chrome renders a checkbox in a container that has a font-size of 10pt.

The problem

Google Chrome seems to render some extra space around a checkbox element that I cannot seem to get rid of. The checkbox and its parent element must be 15 pixels tall. Setting the font-size of the parent element to 10pt causes that parent element to be 16 pixels in height.

An example

Take a look at the snippet below.

I have yet to find out (or understand) what causes the checkbox element to render as 15 pixels tall but effectively making its parent element 16 pixels tall.

td,
th
{
    padding: 0;
    font-size:   10pt;
}

input[type=checkbox]
{
    height: 15px;
    border: none;
    padding: 0;
    margin: 0;
}
<table width="100%" class="data">
    <tr>
        <th>Label 1</th>
        <td>Value 1</td>
    </tr>
    <tr>
        <th>Checkbox 2</th>
        <td><input type="checkbox" disabled="disabled" /></td>
    </tr>
    <tr>
        <th>Label 3</th>
        <td><input type="checkbox" disabled="disabled" checked="checked" /></td>
    </tr>
</table>

Exchanging the table for a div, a p or any other container also results in an incorrect height for that container.

Possible solution?

Setting the checkbox height to 14px makes the parent row 15 pixels tall. But then the checkbox itself does not meet the designer's requirements and thus this solution will not be accepted. Any workarounds?




Make the checkbox behave with radiobutton

Make the checkbox behave like a radiobutton, allowing the checkbox to be deselected. And my select is also part and works the same as the checkbox if the value is greater than 0 the checkbox deselects, if you select a checkbox the select gets 0.

I have such a code in knockoutJS:

   var InternalAuditRecordTopic = function (data) {
                var self = this;
        self.InternalAuditRecordTopicID = ko.observable(data.InternalAuditRecordTopicID);
        self.InternalAuditRecordID = ko.observable(data.InternalAuditRecordID);
        self.Name = ko.observable(data.Name);
        self.Order = ko.observable(data.Order);
        self.Request = ko.observable(data.Request);
        self.NonComformityType = ko.observable(data.NonComformityType);
        self.Comformity = ko.observable(parseInt(data.Comformity));
        self.OM = ko.observable(parseInt(data.OM));
        self.Observation = ko.observable(data.Observation);
        self.Evidences = ko.observable(data.Evidences);          

        self.startPlaceHolders = function () {
            startPlaceHolders();
        };

    };


.....

        ko.cleanNode($("form#internalAuditRecordRegisterForm"));
        var viewModel = new InternalAuditRecord(@Html.Raw(Model.ToJson()));
        ko.applyBindings(viewModel, document.getElementById("internalAuditRecordRegisterForm"));

And in html:

section class="internalAuditRecordTopicDetail with-margin" data-
index="${$index}">
            <input type="hidden" name="InternalAuditRecordTopics[${$index}].Request" value="${Request}" />
            <input type="hidden" name="InternalAuditRecordTopics[${$index}].Name" value="${Name}" />
            <input type="hidden" name="InternalAuditRecordTopics[${$index}].Comformity" value="${Comformity}" />
            <input type="hidden" name="InternalAuditRecordTopics[${$index}].NonComformityType" value="${NonComformityType}" />
            <input type="hidden" name="InternalAuditRecordTopics[${$index}].OM" value="${OM}" />
            <input type="hidden" name="InternalAuditRecordTopics[${$index}].Observation" value="${Observation}" />
            <input type="hidden" name="InternalAuditRecordTopics[${$index}].Evidences" value="${Evidences}" />
            <input type="hidden" name="InternalAuditRecordTopics[${$index}].InternalAuditRecordID" value="${InternalAuditRecordID}" />
            <input type="hidden" name="InternalAuditRecordTopics[${$index}].InternalAuditRecordTopicID" value="${InternalAuditRecordTopicID}" />
            <input type="hidden" name="InternalAuditRecordTopics[${$index}].Order" value="${$index}" />
            <fieldset class="grey-bg relative internalAuditRecordTopic">
                <ul class="mini-menu visible">
                    
                    
                    <li>@Html.UpIcon(null, new { data_bind = "click: $parent.upInternalAuditRecordTopic", @Title = "Subir Item" })</li>
                    
                    
                    <li>@Html.DownIcon(null, new { data_bind = "click: $parent.downInternalAuditRecordTopic", @Title = "Descer Item" })</li>
                    
                    
                    <li>@Html.DeleteIcon(null, new { @Title = "Remover Item", data_bind = "click: $parent.removeInternalAuditRecordTopic" })</li>
                </ul>
                <legend>
                    @*<a href="#" data-bind="text: Name"></a>*@
                    <span>
                        <input type="text" style="width:300px;" class="internalAuditRecordTopicRequest" placeholder="Requisito" data-bind="value:Request" /> 
                    </span>
                </legend>
                <table class="tg" data-id="${$index}">
                    <tr>
                        <td class="tg-yw4l" align="right"><span class="label" style="color:black">Registros da Auditoria: </span></td>
                        <td><span><textarea cols="65" rows="10" style="width:400px;" class="internalAuditRecordTopicName" placeholder="Nome do tópico" data-bind="value:Name" /></span></td>
                    </tr>
                    <tr>
                        <td class="tg-yw4l" align="right"><span for="active" class="label" style="color:black">Comforme: </span></td>
                        <td><input type="checkbox" value="1"  data-bind="checked:Comformity,isSelectedComformity:" class="float-left" /></td>
                    </tr>                   
                    <tr>
                        <td class="tg-yw4l" align="right"><span for="active" class="label" style="color:black">Oportunidade de Melhoria: </span></td>
                        <td><input type="checkbox" value="1" data-bind="checked:OM, isSelectedOM:" class="float-left"/></td>
                    </tr>
                    <tr>
                        <td class="tg-yw4l" align="right"><span class="label" style="color:black">Não Conformidade: </span></td>
                        <td class="tg-yw4l">
                            <span id="span_finished">
                                <select data-bind="value: NonComformityType" id="NonComformityType">
                                    <option value="0" selected>Escolher</option>
                                    <option value="2">Maior</option>
                                    <option value="1">Menor</option>
                                </select>
                            </span>
                        </td>
                    </tr>
                    <tr>
                        <td class="tg-yw4l" align="right"><span class="label" style="color:black">Observações: </span></td>
                        <td><textarea cols="65" rows="10" style="width:400px;" class="internalAuditRecordTopicObservation" placeholder="Observações" data-bind="value:Observation" /></td>
                    </tr>
                    <tr>
                        <td class="tg-yw4l" align="right"><span class="label" style="color:black">Evidências: </span></td>
                        <td><textarea cols="65" rows="10" style="width:400px;" class="internalAuditRecordTopicEvidences" placeholder="Evidências" data-bind="value:Evidences"  id="Evidences" /></td>
                    </tr>
                </table>

What I've already tried:

ko.bindingHandlers.isSelectedOM = {
                init: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
                    if ($(element).is(':checked')) {
                        $(element).closest('table').find(':checkbox').prop('checked', false);
                    }
                },
                update: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
                    if ($(element).is(':checked')) {
         $(element).closest('table').find(':checkbox').prop('checked', false);
                    $(element).closest('table').find('select').prop('value', 0);

                    }
                }
            };




Select checkboxes in a row [on hold]

I need a script that will run on click and check if 4 checkboxes are selected. The important thing that checkboxes must be selected in a row, the order I select them doesn't matter they just must be in a row like: 4,5,6,7 or: 7,8,9,10 and so on. Not sure if this piece of code example will come in handy:

<ul id="checkbox-list">
   <li><input type="checkbox">1</li>
   <li><input type="checkbox">2</li>
   <li><input type="checkbox">3</li>
   <li><input type="checkbox">4</li>
   <li><input type="checkbox">5</li>
   <li><input type="checkbox">6</li>
   <li><input type="checkbox">7</li>
   <li><input type="checkbox">8</li>
   <li><input type="checkbox">9</li>
   <li><input type="checkbox">10</li>
</ul>

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

Thanks




How to count number of checkboxes selected from Telerik ASP MVC Grid cell

I'm using Telerik ASP.Net MVC Grid and I have checkboxes in each cell (5 checkboxes). When checkbox change state (selected or deselected) I want to get the number of selected checkboxes and update my database table.And when I refresh the grid or close and reopen the application, I should find that the selected checkboxes are always selected (read from database the number of selected checkboxe in every cell). How can I do this?

Grid code:

    @(Html.Kendo().Grid<SereneQM.Models.TableauCtrlMesureCm>()
.Name("myGrid")

   .Columns(columns =>
   {
       columns.ForeignKey(o => o.ElementsMesureId, (System.Collections.IEnumerable)ViewData["elementsMesure"], "ElementsMesureId", "Name").Title("Mesure de").Width("130px");

       columns.Bound(e => e.C_3).ClientTemplate("<input type='checkbox' value='C_3_1' id= 'C_3_c1' class='chkbx' onclick='c_3_1ChkBoxClick();' /> <input type='checkbox' value='@item.C_3'  @(item.C_3=='True' ? 'checked= checked' name='chx_3_2' id='C_3_c2'  class='chkbx' onclick='c_3_2ChkBoxClick() ;' /> <input type='checkbox' #= C_3 ? checked='': '' # class='chkbx' id= 'C_3_c3' onclick='c_3_3ChkBoxClick() ;' /> <input type='checkbox' #= C_3 ? checked='': '' # class='chkbx' id= 'C_3_c4' onclick='c_3_4ChkBoxClick() ;' /> <input type='checkbox' #= C_3 ? checked='': '' # class='chkbx' id= 'C_3_c5' onclick='c_3_5ChkBoxClick() ;' />")
             .HtmlAttributes(new { style = "text-align: center" }).Title("-3").Width(50);


       columns.Bound(e => e.C_2_5).ClientTemplate("<input class='chkbx' type='checkbox' id= 'C_2_5_c1'/> <input class='chkbx' type='checkbox' id= 'C_2_5_c2'/>")
        .HtmlAttributes(new { style = "text-align: center" }).Title("-2.5").Width(50);

       columns.Bound(e => e.C_2).ClientTemplate("<input type='checkbox' #= C_2 ? checked='': '' # class='chkbx' onclick='c_2ChkBoxClick();'/> <input type='checkbox' #= C_2 ? checked='': '' # class='chkbx' onclick='c_2ChkBoxClick();'/> <input type='checkbox' #= C_2 ? checked='': '' # class='chkbx'onclick='c_2ChkBoxClick();' /> <input type='checkbox' #= C_2 ? checked='': '' # class='chkbx' onclick='c_2ChkBoxClick();'/> <input type='checkbox' #= C_2 ? checked='': '' # class='chkbx' onclick='c_2ChkBoxClick();'/>")
         .HtmlAttributes(new { style = "text-align: center" }).Title("-2").Width(50);

       columns.Bound(e => e.C_1_5).ClientTemplate("<input type='checkbox' #= C_1_5 ? checked='': '' # class='chkbx' onclick='c_1_5ChkBoxClick();'/> <input type='checkbox' #= C_1_5 ? checked='': '' # class='chkbx' onclick='c_1_5ChkBoxClick();'/> <input type='checkbox' #= C_1_5 ? checked='': '' # class='chkbx' onclick='c_1_5ChkBoxClick();'/> <input type='checkbox' #= C_1_5 ? checked='': '' # class='chkbx' onclick='c_1_5ChkBoxClick();'/> <input type='checkbox' #= C_1_5 ? checked='': '' # class='chkbx' onclick='c_1_5ChkBoxClick();'/>")
         .HtmlAttributes(new { style = "text-align: center" }).Title("-1.5").Width(50);

       columns.Bound(e => e.C_1).ClientTemplate("<input type='checkbox' #= C_1 ? checked='': '' # class='chkbx' onclick='c_1ChkBoxClick();'/> <input type='checkbox' #= C_1 ? checked='': '' # class='chkbx' onclick='c_1ChkBoxClick();'/> <input type='checkbox' #= C_1 ? checked='': '' # class='chkbx' onclick='c_1ChkBoxClick();'/> <input type='checkbox' #= C_1 ? checked='': '' # class='chkbx' onclick='c_1ChkBoxClick();'/> <input type='checkbox' #= C_1 ? checked='': '' # class='chkbx' onclick='c_1ChkBoxClick();'/>")
         .HtmlAttributes(new { style = "text-align: center" }).Title("-1").Width(50);

       columns.Bound(e => e.C_0_5).ClientTemplate("<input type='checkbox' #= C_0_5 ? checked='': '' # class='chkbx' onclick='c_0_5ChkBoxClick();'/> <input type='checkbox' #= C_0_5 ? checked='': '' # class='chkbx' onclick='c_0_5ChkBoxClick();'/> <input type='checkbox' #= C_0_5 ? checked='': '' # class='chkbx' onclick='c_0_5ChkBoxClick();'/> <input type='checkbox' #= C_0_5 ? checked='': '' # class='chkbx' onclick='c_0_5ChkBoxClick();'/> <input type='checkbox' #= C_0_5 ? checked='': '' # class='chkbx' onclick='c_0_5ChkBoxClick();'/>")
         .HtmlAttributes(new { style = "text-align: center" }).Title("-0.5").Width(50);

       columns.Bound(e => e.C0).ClientTemplate("<input type='checkbox' #= C0 ? checked='': '' # class='chkbx' onclick='c0ChkBoxClick();'/> <input type='checkbox' #= C0 ? checked='': '' # class='chkbx' onclick='c0ChkBoxClick();'/> <input type='checkbox' #= C0 ? checked='': '' # class='chkbx' onclick='c0ChkBoxClick();'/> <input type='checkbox' #= C0 ? checked='': '' # class='chkbx' onclick='c0ChkBoxClick();'/> <input type='checkbox' #= C0 ? checked='': '' # class='chkbx' onclick='c0ChkBoxClick();'/>")
         .HtmlAttributes(new { style = "text-align: center" }).Title("0").Width(50);

       columns.Bound(e => e.C0_5).ClientTemplate("<input type='checkbox' #= C0_5 ? checked='': '' # class='chkbx' onclick='c0_5ChkBoxClick();'/> <input type='checkbox' #= C0_5 ? checked='': '' # class='chkbx' onclick='c0_5ChkBoxClick();'/> <input type='checkbox' #= C0_5 ? checked='': '' # class='chkbx' onclick='c0_5ChkBoxClick();'/> <input type='checkbox' #= C0_5 ? checked='': '' # class='chkbx' onclick='c0_5ChkBoxClick();'/> <input type='checkbox' #= C0_5 ? checked='': '' # class='chkbx' onclick='c0_5ChkBoxClick();'/>")
         .HtmlAttributes(new { style = "text-align: center" }).Title("0.5").Width(50);

       columns.Bound(e => e.C1).ClientTemplate("<input type='checkbox' #= C1 ? checked='': '' # class='chkbx' onclick='c1ChkBoxClick();'/> <input type='checkbox' #= C1 ? checked='': '' # class='chkbx' onclick='c1ChkBoxClick();'/> <input type='checkbox' #= C1 ? checked='': '' # class='chkbx' onclick='c1ChkBoxClick();'/> <input type='checkbox' #= C1 ? checked='': '' # class='chkbx' onclick='c1ChkBoxClick();'/> <input type='checkbox' #= C1 ? checked='': '' # class='chkbx' onclick='c1ChkBoxClick();'/>")
         .HtmlAttributes(new { style = "text-align: center" }).Title("1").Width(50);

       columns.Bound(e => e.C1_5).ClientTemplate("<input type='checkbox' #= C1_5 ? checked='': '' # class='chkbx' onclick='c1_5ChkBoxClick();'/> <input type='checkbox' #= C1_5 ? checked='': '' # class='chkbx' onclick='c1_5ChkBoxClick();'/> <input type='checkbox' #= C1_5 ? checked='': '' # class='chkbx' onclick='c1_5ChkBoxClick();'/> <input type='checkbox' #= C1_5 ? checked='': '' # class='chkbx' onclick='c1_5ChkBoxClick();'/> <input type='checkbox' #= C1_5 ? checked='': '' # class='chkbx' onclick='c1_5ChkBoxClick();'/>")
         .HtmlAttributes(new { style = "text-align: center" }).Title("1.5").Width(50);

       columns.Bound(e => e.C2).ClientTemplate("<input type='checkbox' #= C2 ? checked='': '' # class='chkbx' onclick='c2ChkBoxClick();'/> <input type='checkbox' #= C2 ? checked='': '' # class='chkbx' onclick='c2ChkBoxClick();'/> <input type='checkbox' #= C2 ? checked='': '' # class='chkbx' onclick='c2ChkBoxClick();'/> <input type='checkbox' #= C2 ? checked='': '' # class='chkbx' onclick='c2ChkBoxClick();'/> <input type='checkbox' #= C2 ? checked='': '' # class='chkbx' onclick='c2ChkBoxClick();'/>")
         .HtmlAttributes(new { style = "text-align: center" }).Title("2").Width(50);

       columns.Bound(e => e.C2_5).Title("2.5").ClientTemplate("<input type='checkbox' #= C2_5 ? checked='': '' # class='chkbx' onclick='c2_5ChkBoxClick();'/> <input type='checkbox' #= C2_5 ? checked='': '' # class='chkbx' onclick='c2_5ChkBoxClick();'/> <input type='checkbox' #= C2_5 ? checked='': '' # class='chkbx' onclick='c2_5ChkBoxClick();'/> <input type='checkbox' #= C2_5 ? checked='': '' # class='chkbx' onclick='c2_5ChkBoxClick();'/> <input type='checkbox' #= C2_5 ? checked='': '' # class='chkbx' onclick='c2_5ChkBoxClick();'/>")
         .HtmlAttributes(new { style = "text-align: center" }).Width(50);

       columns.Bound(e => e.C3).Title("3").ClientTemplate("<input type='checkbox' #= C3 ? checked='': '' # class='chkbx' onclick='c3ChkBoxClick();'/> <input type='checkbox' #= C3 ? checked='': '' # class='chkbx' onclick='c3ChkBoxClick();'/> <input type='checkbox' #= C3 ? checked='': '' # class='chkbx' onclick='c3ChkBoxClick();'/> <input type='checkbox' #= C3 ? checked='': '' # class='chkbx' onclick='c3ChkBoxClick();'/> <input type='checkbox' #= C3 ? checked='': '' # class='chkbx' onclick='c3ChkBoxClick();'/>")
         .HtmlAttributes(new { style = "text-align: center" }).Width(50);

       columns.Bound(e => e.MD).Title("M.D").Width(50);
   })

    .DataSource(dataSource => dataSource
        .Ajax()
        .Group(g => g.Add(p => p.Size))
        .Batch(true)
        .ServerOperation(false)
        .AutoSync(true)

.Events(events => events.Error("error_handler").RequestEnd("onGridDataSourceRequestEnd"))
.Model(model =>
{
    model.Id(p => p.Id);
    model.Field(p => p.Id);
    model.Field(p => p.C_3).Editable(false);
    model.Field(p => p.C_2_5).Editable(false);
    model.Field(p => p.C_2).Editable(false);
    model.Field(p => p.C_1_5).Editable(false);
    model.Field(p => p.C_1).Editable(false);
    model.Field(p => p.C_0_5).Editable(false);
    model.Field(p => p.C0).Editable(false);
    model.Field(p => p.C0_5).Editable(false);
    model.Field(p => p.C1).Editable(false);
    model.Field(p => p.C1_5).Editable(false);
    model.Field(p => p.C2).Editable(false);
    model.Field(p => p.C2_5).Editable(false);
    model.Field(p => p.C3).Editable(false);
})

   .Read(read => read.Action("Tab_Read", "Home").Data("getData"))
   .Create(create => create.Action("Tab_Create", "Home").Data("getData"))
   .Update(update => update.Action("Tab_Update", "Home"))
   .Destroy(destroy => destroy.Action("Tab_Destroy", "Home"))
        )
    .Scrollable()
    .HtmlAttributes(new { style = "height: 550px" })
    .Editable(editable => editable.Mode(GridEditMode.InCell))
    .Selectable()
    .Sortable()
                )

The "getData" is javascript method that content the values to add/update the database. Take a look to this screenshot to better interstand.

Grid view screenshot

Database table screenshot




Reminder check box not selected first Time in swift

image here

I am new to swift I can used reminder check box in login page working fine,

  1. when Reminder checkBox select show the credential in log text Field it's working
  2. when Reminder checkBox unselect credential is clear from the log text Field working

but when logout after if i can click reminder checkbox to unselect the reminder checkBox it's not selecting first time when I click Double its selecting,

this is the code

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)


      let checkviewapper = UserDefaults.standard
      let logindata = UserDefaults.standard
      let data = checkviewapper.integer(forKey:"checked")

        print("data values is ",data)
        if(data == 1)
        {

          RmdButton.setImage( UIImage(named:"check.png"), for: .normal)
          emailText.text = logindata.string(forKey: "emaild_default")
          passwordText.text = logindata.string(forKey: "password_default")

        }
        else
        {

            emailText.text = ""
            passwordText.text = ""
            RmdButton.setImage( UIImage(named:"uncheck.jpeg"), for: .normal)

        }
    }


    @IBAction func checkBox(_ sender: UIButton) {


        let defautls = UserDefaults.standard
        defautls.removeObject(forKey:"checked")

        defautls.synchronize()

       if unchecked {


             let defautls = UserDefaults.standard
             defautls.set(unchecked, forKey: "checked")
             defautls.synchronize()

            if let myLoadedString = defautls.string(forKey: "checked") {

            }

            sender.setImage( UIImage(named:"check.png"), for: .normal)
            print("checked inside")
            unchecked = false
        }
        else {
            sender.setImage( UIImage(named:"uncheck.jpeg"), for: .normal)
            print("uncheckinside")
            unchecked = true
        }

    }

where I did mistake, how to set the reminder CheckBox uncheck at First Time pls help me.....!