vendredi 22 décembre 2017

Execute funcionts if checkbox is checked or uncheked ? Angular

i have a table with x records, from table i want add items into array (or remove if uncheck row) but i dont know how to execute functions according if checkbox is true or not... but this not work

<tr ng-repeat="item in vm.orders" ng-click="vm.getRow(item)">
  <td></td>
  <td></td>
  <td><input type="checkbox" 
             ng-true-value="vm.addToArray(item)" 
             ng-false-value="vm.removeFromArray(item)" 
  /></td>
</tr>

controller:

function addToArray(model) {
    vm.selectedItems.push(model);
}

function removeFromArray(model) {
   //my logic remove
}




Get the first value from comma separated string in jquery

I am trying to create a filter option like this :

enter image description here

I am able to get the values from the comma separated string but not as expected as show below : enter image description here

On each click of checkbox on the left side I am getting the value of that checkbox and show it on the top right side. In case I select Option1, It shows Option1, then If I select Option2, then it shows Option1,Option1,Option2. I wish remove that Option1 at the beginning.

Below is my code:

 
$('input[type="checkbox"]').change(function()
                { 

                        if(!$(this).is(':checked'))
                           $('.badge li').remove();

                        var favorite = [];
            
            $.each($("input[name='category']:checked"), function(){            
                favorite.push($(this).val());
            });
            
            var selecte = favorite.join(",")[0];


            $(".badge").append($("<li>").css({float:'left'}).html(selecte));

                        var itemName = $('select option:selected').text(); 

                $('.uncheckall').show();

                        $('.smallapply').show();

                        var textinputs = document.querySelectorAll('input[type=checkbox]');

                        var empty = [].filter.call( textinputs, function( el )
                        {
                           return !el.checked
                        });

                        if (textinputs.length == empty.length)
                        {                           
                            $('.uncheckall').hide();

                                $('.smallapply').hide();
                        }

                });     
<ul class="list-unstyled scrollbar" id="style-3">

                 <li>
                  <label class="custom-control custom-checkbox">
                  <input type="checkbox" name="category" id="checkbox1" value="option1" class="custom-control-input">
                  <small class="custom-control-indicator"></small>
                  <small class="custom-control-description">Option1</small>
                  </label>
                </li>

                <li>
                 <label class="custom-control custom-checkbox">
                 <input type="checkbox" name="category" id="checkbox2" value="option2" class="custom-control-input">
                 <small class="custom-control-indicator"></small>
                 <small class="custom-control-description">Option2</small>
                </label>
           </li>

           <li>
                <label class="custom-control custom-checkbox">
                <input type="checkbox" name="category" id="checkbox3" value="option3" class="custom-control-input">
                <small class="custom-control-indicator"></small>
                <small class="custom-control-description">Option3</small>
                </label>
           </li>
     </ul>



WPF Checkbox Command for Unchecked and Checked

I have the following line in a .XAML file:

<CheckBox x:Name="checker"  Grid.Column="1" Grid.Row="6" Command="{Binding LoadCommand}"></CheckBox>

Now my question is - what is the best way to have different Commands for the checkbox "checked" and checkbox "unchecked".

In my ViewModel I have two different functions (LoadCommand and LoadActiveCommand), one should be loaded when the checkbox is checked and the other when the checkbox is unchecked.

What is the best way to get the result I wish? Is there a way to do it directly in the .XAML file or do I have to do this in xaml.cs?




Python: Add checkbox in Excel cell using PyWin32 and VBA code

I am trying to add a checkbox in certain cells in an excel sheet. I am opening an existing sheet using win32com

I can't really find any solutions when googling, the closest i have come is this question:

python: how to insert checkbox in excel?

Where he apparently found a solution himself using VBA code, but didn't post the solution. I have tried similar stuff by doing:

Sheet.CheckBoxes.Add()

But i get an error saying that function CheckBoxes has no attribute "Add". Ideally i want to do something like this:

Sheet.CheckBoxes.Add(row, col)

How can i go about doing that?




jeudi 21 décembre 2017

How to get dynamic control checkbox in client side?

In .net server side i was creating Dynamic controls text-box,checkbox. If i click the checkbox inside all the checkbox list controls it should get checked. refer this image.

server side using new EventHandler i can achieve this.But i want this in clientside.

Clientside code :

function CheckboxHeaderClick1() {

    var chkBox = "<%=strchx1ID %>";
    if (chkBox.checked) {
        var checkboxList = "<%=strchxboxlist1ID %>"; 
        var chkBoxCount = "<%=strchxboxlist1Count %>";
        for (var i = 0; i < chkBoxCount.length; i++) {
            chkBoxCount[i].checked = true;
        }
    }
    else {
        var checkboxList = "<%=strchxboxlist1ID %>"; 
        var chkBoxCount = "<%=strchxboxlist1Count %>";
        for (var i = 0; i < chkBoxCount.length; i++) {
            chkBoxCount[i].checked = false;
        }
    }
}

but chkBox.checked is coming undefined.From server side to client side how i can pass the checkbox control?

enter image description here

enter image description here

My code :

  System.Web.UI.WebControls.Label lbllookup = new System.Web.UI.WebControls.Label();
                                                            Panel pnl1 = new Panel();

                                                                    chx1 = new CheckBox();
                                                                chx1.ID = "chx" + fieldname;
                                                                strchx1ID = chx1.ClientID;
                                                             //   chx1.AutoPostBack = true;
                                                                if (!IsPostBack)
                                                                    chx1.Checked = true;
                                                               // chx1.CheckedChanged += new EventHandler(this.chx1_CheckedChanged);
                                                               // chx1.Attributes.Add("onclick", "CheckboxHeaderClick1();");
                                                                chx1.Attributes.Add("onclick", "javascript:CheckboxHeaderClick1();return false;");
                                                                checkboxID = chx1.ID;
                                                                chx1.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#f2f2f2");
                                                                chx1.Style.Add(HtmlTextWriterStyle.Color, "#287082");

                                                                chx1.Style.Add(HtmlTextWriterStyle.PaddingBottom, "6px");

                                                                chx1.Style.Add(HtmlTextWriterStyle.FontSize, "14px!important;");
                                                                pnl_filters.Controls.Add(chx1);
                                                                lookupfieldcount++;
                                                                chxboxlist1 = new CheckBoxList();
                                                                chxboxlist1.ID = fieldname;
                                                                strchxboxlist1ID = chxboxlist1.ClientID;

//chx1.CheckedChanged += new EventHandler(this.chx1_CheckedChanged);                                                                 lbllookup.Text = field.Title;
                                                                lbllookup.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#f2f2f2");
                                                                lbllookup.Style.Add(HtmlTextWriterStyle.Color, "#287082");
                                                                //lbllookup.Style.Add(HtmlTextWriterStyle.PaddingLeft, "8px");
                                                                //lbllookup.Style.Add(HtmlTextWriterStyle.PaddingTop, "4px");
                                                                lbllookup.Style.Add(HtmlTextWriterStyle.PaddingBottom, "6px");
                                                                //  lbllookup.Style.Add(HtmlTextWriterStyle.PaddingRight, "142px");
                                                                lbllookup.Style.Add(HtmlTextWriterStyle.FontSize, "14px!important;");
                                                                lbllookup.Style.Add(HtmlTextWriterStyle.Width, "240px");
                                                                pnl_filters.Controls.Add(lbllookup);


                                                                pnl1.ID = "pnl" + fieldname;
                                                                if (chxboxlist1.Height == 105)
                                                                {
                                                                    pnl1.Style.Add(HtmlTextWriterStyle.Height, "105px");
                                                                    pnl1.Style.Add(HtmlTextWriterStyle.OverflowY, "scroll");
                                                                }
                                                                else
                                                                {
                                                                    pnl1.Style.Add(HtmlTextWriterStyle.Height, "90px");
                                                                }
                                                                pnl_filters.Controls.Add(pnl1);
                                                                pnl1.Controls.Add(chxboxlist1);

                                                                if (!IsPostBack)
                                                                    bind_Fields(fieldname, listtitle, lookupfield, chxboxlist1);
                                                                if (chxboxlist1.Items.Count == 0)
                                                                    bind_Fields(fieldname, listtitle, lookupfield, chxboxlist1);
                                                                checkboxcount++;




Cocoa Immutable CheckBox

I have a window that is displaying some info about a file - including whether it's a package or an alias. I'm currently using a checkbox, but since you can't set those values, I don't want the checkbox to be editable. I know I can set it to disabled, but I don't actually want it disabled. Is there a way to just make it immutable in the UI or a better control that I could use to display that info?




Android ListView CheckBox repetition

i have a problem related to using checkbox in a dynamic listview. I checked similar questions and their answers and tried to adjust my code. Unfortunately, i couldn't get over it.

Briefly, at the begining my checks on the list was disappeared when i scrolled the list. Later on i made some changes on its codes and this time when i clicked on the first item on the list, checkbox repeated every 6th items without clicking on them.

Book.java

package book.lib;

public class Books {

private String title;
private String image;
private Boolean checkbox;

public Books() {

}

//Getters and setters
public String getTitle() {
    return title;
}
public void setTitle(String title) {
    this.title = title;
}
public String getImage() {
    return image;
}
public void setImage(String image) {
    this.image = image;
}

public Boolean getCheckbox() {
    return checkbox;
}
public void setCheckbox(boolean checkbox) {
    this.checkbox = checkbox;
}

}

BookAdapter.java

public class BookAdapter extends ArrayAdapter<Books> {
private final Context context;
private ArrayList<Books> bookList;

LayoutInflater vi;
int Resource;
ViewHolder holder = null;
GetBookThumb getBookThumb;

public BookAdapter(Context context, int resource, ArrayList<Books> objects) {
    super(context, resource, objects);
    vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    Resource = resource;
    bookList = objects;
    getBookThumb=new GetBookThumb(context);
    this.context = context;

}

public int getCount() {
    return bookList.size();
}

public Books getItem(int position) {
    return bookList.get(position);
}
@Override

public long getItemId(int position) {
    return position;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    // convert view = design
    View v = convertView;

    if (v == null) {
        holder = new ViewHolder();
        v = vi.inflate(Resource, null);

        holder.bookIMG = (ImageView) v.findViewById(R.id.thumb);
        holder.bookTITLE = (TextView) v.findViewById(R.id.book_title);
        holder.checkBox = (CheckBox) v.findViewById(R.id.checkBox);

        v.setTag(holder);

    } else {
        holder = (ViewHolder) v.getTag();
        getBookThumb.DisplayImage(bookList.get(position).getImage(), holder.bookIMG);
        holder.bookTITLE.setText(bookList.get(position).getTitle());
        holder.checkBox.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Books book = bookList.get(position);
                book.setCheckbox(holder.checkBox.isChecked());
                Toast.makeText(context.getApplicationContext(),

                        "Clicked on Checkbox: " + holder.checkBox.getText() +
                                " is " + holder.checkBox.isChecked(),
                        Toast.LENGTH_LONG).show();
            }
        });
    }
        return v;

}
static class ViewHolder {
    public ImageView bookIMG;
    public TextView bookTITLE;
    public CheckBox checkBox;
}

}