mardi 2 mai 2017

How to save ids and boolean value checkbox_tag Ruby on Rails

I am currently trying to implement an attendance sheet where the user ticks a checkbox next to the user's name; if checked user is present, if unchecked user is absent.

I currently have it working where the attendance sheet lists all users attending the event however, it only saves the attendance id and user id of the checkboxes ticked.

I want the attendance sheet to save all user ids and assign a boolean value to each.

My current view:

 <%= simple_form_for @attendance, :html=> { :multipart=> true } do |f| %>

<div class="checkBoxes">
    <div>
        <%= f.hidden_field :event_id, :value => @event.id %>

    </div>


    <div >
        <% @event.users.each do |user| %>

         <%= check_box_tag "attendance[user_ids][]",user.id,attendance.users.include?(user) %>
            <%= user.name %><br>
    <% end %>
        </div>
    </div>



<div class="actions">
   <%= f.button :submit, 'Save', class: "btn btn-primary" %>
  </div>
<% end %>

The form saves the selected event id and date in an attendances table and then builds the attendance_id and user_id under the attendance_users table.

Database migration for attendance users:

class CreateAttendanceUsers < ActiveRecord::Migration
  def change
    create_table :attendance_users do |t|

      t.integer :attendance_id, :null => false
      t.integer :user_id, :null =>false
      t.boolean :is_absent

      t.timestamps
    end
  end
end

It currently only saves the attendance_id and user_id of the selected checkboxes. How can I:
1.) Save all checked and unchecked users?
2.) Assign each user a boolean value(if checked is_absent is false, if unchecked is_absent is true




check a checkbox from database in php

I want to choose a group from a dropdown and populate a checkboxlist according to that chosen group. Each group have different locals and those locals are defined on my database.If someone can help my on how can i check the checkbox's from each group. Images with code.

Array of locals, web




ng-click or ng-change don't save array

I have a new auction form. The user has to insert all the requested field , then by clicking on a button "Invite People" can invite other saved users or can invite people by e mail. The email part works fine. But the users part give me some problem.

The html part:

          <div ng-show="showBid" class="panel panel-default" ng-controller="NewAuctionController">
<div class="panel-heading">Invite Members</div>
<div class="panel-body">
    <ul class="list-group" ng-repeat="user in users">
        <li class="col-md-4" id="userlist" ng-hide="user.name == profile">
            <img ng-src="" class="userImage">
            <div class="username"> </div>
            <div class="userrole">  </div>
            <div class="usercompany"></div>
            <input type="checkbox" ng-model="user.isChecked" ng-click="insertinvited(user)">

</li>
</ul>

The above part i tried also with ng-change, but it's the same. The insertinvited() is:

                $scope.invitations=[];

$scope.insertinvited= function (user) {

    if(user.isChecked) {
        $scope.invitations.push(user.name);
    } else {
        var toDel = $scope.invitations.indexOf(user);
        $scope.invitations.splice(toDel);
    }
    console.log($scope.invitations);

};

In the console this works, cause when i check the box the array is pushed correctly

But when i try to use that array here:

<div ng-show="showBid" class="panel panel-default" >
    <div class="panel-heading">Members Selected:</div>
    <div class="panel-body">
        <ul class="list-group">
            <li class="list-group-item" ng-repeat="invitation in invitations">
                <div class="listmail"> </div>

            </li>
        </ul>
    </div>
</div>

The array seems to be empty, infact when i pass the array to the controller and i try to do a console.log the array is empty. Anyone could me help?




How to display checkbox values on screen if it is checekd using formGroup Angular2

I am angular2 beginner. I am try to display checkbox values on screen if checkbox is checked and checkbox is unchecked so remove the value. I am use formGroup and formArray in angular2.

Html code here :-

<form [formGroup] = "testForm">

  <div formArrayName="extras">
    <span  *ngFor="let extra of extras; let i = index" formGroupName="">
        <label class="btn btn-primary" formControlName="" btnCheckbox  [(ngModel)] = "extra.status"></label>
    </span> 
  </div>
</form>
<!-- Display values of extras -->
<div *ngIf="getFormValues?.extras">
   <span  *ngFor="let extra of getFormValues?.extras; let i = index>
     
   </span>
</div>

Component.ts code here

extras:any = [
  { value: 'good', display: 'good', status: 'false'},
  { value: 'bed', display: 'bed', status: 'false'},
  { value: 'nice', display: 'bed', status: 'false'},
]

let allextras: FormArray = new FormArray([]);
for (let i = 0; i < this.extras.length; i++) {
  let fg = new FormGroup({});
  fg.addControl(this.extras[i].value, new FormControl(false))
  allextras.push(fg)
}

this.testForm.valueChanges.subscribe( (form: any) => {
  this.getFormValues = form;
});

This code is work well but does not display value of checkbox if checked the checkbox and visa versa. Thanks!




mvc razor view checkbox change event listbox select all not working

I am working on a mvc 4 application which has a checkbox and listbox in cshtml page. when user check the checkbox I am running change event and making attribute property select as select for all items in listbox and unselecting on uncheck. Every thing is working fine until user repeat same process, I mean re checking the checkbox not selecting the items in listbox.

Here is my code, could you please provide your inputs on fixing this issue.

<script type="text/javascript">
    $(document).ready(function () {
        $('#chkitems').change(function () {
            debugger;
            if ($(this).is(':checked')) {
                $('#files').each(function () {
                    $("#files option").attr("selected", "selected");
                });
            }
            else {
                $('#files').each(function () {
                    $("#files option").attr("selected", false);
                });
            }

        });
        });
  </script>




lundi 1 mai 2017

Show data from multiple checkbox in codeigniter

i hope all of you can help me to solve my application problem

my problem is when i would like to show data from my multiple checkbox , data success to show but just showing my first data that i have check. example is i check data 1 , data 2 , data 3, but the only data 1 are showing on my page.

my controller :

function comparison()
    {
        if ($this->input->post('submit')) {
            foreach ($id_product = $this->input->post('id_product') as $rm) {
                $show_compare = $this->Compare->start_compare($rm);
            }
            $data['comparison'] = $show_compare;
            $data['title'] = "Comparison";
            $data['meta_keywords'] = ". . .";
            $data['meta_descriptions'] = ". . .";
            $this->load->view('theme/comparison',$data);
        }
    }

My Model :

function start_compare($id_product)
    {
        $this->db->select('product.id_subcategory,product.type,product.product_name,specificcategory.specificcategory_name,specification_biostar.*');
        $this->db->join('specification_biostar', 'specification_biostar.id_product = product.id_product', 'left');
        $this->db->join('specificcategory', 'specificcategory.id_specificcategory = product.id_subcategory', 'left');
        $this->db->where('product.id_product', $id_product);
        $sql = $this->db->get('product')->result_array();
        return $sql;
    }

my view (option multiple-checkbox) :

<div class="box-body">
     <input type="checkbox" name="id_product[]" id="txt" onClick="EnableSubmit3(this)" value="<?php echo $row['id_product']; ?>"><label>Choose</label>
     </div>

my view (result data) :

 <table class="table">
                <?php foreach ($comparison as $row){ ?>
                <tr>
                    <td colspan="2"><?php echo $row['id_product'] ?></td>
                </tr>
                <?php } ?>
            </table>




text view with checkbox,if i clear the text view the checkbox should be unchecked in android

when I select the checkboxes the selected checkbox item is displaying in the text view.it works fine, but when I clear the text view, it should be unchecked while I am clearing the text