vendredi 27 mars 2015

Dynamic checkbox generation in android

I need to generate two reference checkboxes(that i put already in the xml given below) for two different objects.one checkbox reference(from one checkbox can generate based on the number of objects) is worked fine but for the second checkbox it is showing right to the first one...Using that single refrence(id given for a checkbox) i can create a lot of checkboxes dynamically...it is also working fine....but the second checkboxes must have to show under the first one's created...but it is showing right side to the screen and right side to first ones.Can anyone please help.....



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="#4D000000"
>
<TableRow
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center_horizontal">

<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="CheckBox" />
</TableRow>

<TableRow
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center_horizontal">
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="CheckBox" />
</TableRow>
</LinearLayout>




Value of Hidden Asp.net checkbox field

I have a asp.net checkbox control inside a grid. From Codebehind I am making that checkbox property visible="false".


On Page Load I am setting this checkbox column checked value as true. But when I click save on a that page and access the value of that checkbox field I am getting the checked value as false. Is it an intended behavior? As I believe we should still get the checked value as true irrespective of the checkbox column's visible property. Any Suggestions would be appreciated





Dynamic Checkbox List in Yii2

So I'm trying to create a dynamic Checkbox List in Yii2. I'm trying to adept the work done here but without success. As described there i should use the ArrayHelper.


So first I am fetching the data (works)



$listData=ArrayHelper::map(EinsatzorteModel::find()->asArray()->all(),'id','location');


Output(shortend):



array(9) {
[1]=> string(18) "Region: Y"
[2]=> string(17) "Region: X"
}


Now I'm trying to add it to a checkbox list:



<?= $form ->field($model, 'locations[]')
->checkboxList(
[$listData]
)->label('Regionen');
?>


Which errors to:



htmlspecialchars() expects parameter 1 to be string, array given



Obviously its an Array, but shouldn't it fit anyway? The checkbosList expects parameters to be given as



'A' => 'Item A'


which actually should fit the format from the ArrayHelper.


So where do I get it wrong?





Knockout, select all checkboxes and view list of select checkboxes

I have a list with checkboxes, when I click at one of them, it is displayed in theSelectedUsers, works as it should, and checkboxes data-bind="checked: AllChecked" will checked too, but it should not be.



<div data-bind="foreach: SelectedUsers">
<p>
<span data-bind="text: userName" ></span>
</p>
</div>


But, when I use data-bind="checked: AllChecked", nothing is displayed in SelectedUsers, after that, when I click on some checkbox, all items are selected in the list and nothing is displayed in SelectedUsers


What's wrong? example: http://ift.tt/1FPZGuz



<div id="sideB">
<div data-bind="foreach: AllUsers">
<label>
<input type="checkbox" name="checkedUser" data-bind="value: userName, checked:$root.selectedUserNames" />
<span data-bind="text: userName" ></span>
</label>
</div>
Selected
<div data-bind="foreach: SelectedUsers">
<p>
<span data-bind="text: userName" ></span>
</p>
</div>
<label><input type="checkbox" data-bind="checked: AllChecked" />Check all</label>
</div>


Knockout-3.3.0:



function User(data) {
this.userName = ko.observable(data.userName);
this.selected = ko.observable(data.selected);

}

var dataSource = [new User({userName: "Bill", selected: false}),
new User({userName: "Andrii", selected: false})
];

function UsersViewModel() {
var self = this;
self.AllUsers = ko.observableArray(dataSource);
self.SelectedUsers = ko.observableArray([]);

self.selectedUserNames = ko.observableArray([]);

self.selectedUserNames.subscribe(function(newValue) {
var newSelectedUserNames = newValue;
var newSelectedUsers = [];
ko.utils.arrayForEach(newSelectedUserNames, function(userName) {
var selectedUser = ko.utils.arrayFirst(self.AllUsers(), function(user) {
return (user.userName() === userName);
});
newSelectedUsers.push(selectedUser);
});
self.SelectedUsers(newSelectedUsers);
});

self.AllChecked = ko.computed({
read: function() {
var firstUnchecked = ko.utils.arrayFirst(dataSource, function(item) {
return self.selectedUserNames() == false;
});
return firstUnchecked == null;
},
write: function(value) {
ko.utils.arrayForEach(dataSource, function(item) {
self.selectedUserNames(value);
});
}
})
}

ko.applyBindings(new UsersViewModel(), document.getElementById('sideB'));




Model Binding with Checkboxes in MVC

I have a "Product Create" page and I need to add a Color porperty to it. One product might have more than one color, So I have written a seperate Color model and a ProductColorRelations model. With these models, I can bind many colors to a product.



public class ProductDetailViewModel
{
public AY_PRODUCT product { get; set; }
public List<AY_COLOR> colors { get; set; }
}


// ACTION ON LOAD
public ActionResult ProductsCreate()
{
ProductDetailViewModel mdl = new ProductDetailViewModel();
mdl.product = new AY_PRODUCTS();

mdl.colors = (from g in db.AY_COLORS select g).ToList();

return View(mdl);
}

[HttpPost]
public ActionResult ProductsCreate(ProductDetailViewModel prod_)
{
if (ModelState.IsValid)
{
db.AY_PRODUCTS.Add(prod_.product);
db.SaveChanges();
int ProductId= prod_.product.ID;

//HOW CAN I GET THE VALUES OF SELECTED COLORS HERE?

return RedirectToAction("ProductsCreate");
}
else
{
return View(prod_);
}
}


and here is my view which I couldnt complete.



<% foreach (var item in mdl.colors) { %>
<%: Html.CheckBox( <!-- what exactly ?????? -->) %>
<% } %>


How should I write the view and Action to get the values of selected checkboxes. Please help...





jeudi 26 mars 2015

how to insert textfield just the checked only to database? [on hold]

I have form like this



<form method="post" action="function.php">
<input type="text" name="pcs[]" value="<?php echo $data['pcs']; ?>">Pcs
<input type="checkbox" name="id[]" value="<?php echo $data['id']; ?>">
</form>


i have two tables in my databse, i want insert my second db with the first value db, but i just want insert the value with the new value from the textfield was im checked.


and i have insert funtion page like this...



<?php
include('connect.php'); //connect database

$id= $_POST['id'];
$pcs= $_POST['pcs'];
$pcscount=count($id); //count the checked
if (empty($pcscount))

{
echo"<script>alert('Sorry, at least Choose 1');document.location='order.php';
</script>";
break;
} // must checked at least 1 checkbox

for($no=0;$no<$pcscount;$no++) {

$pcs[$no] = mysql_real_escape_string($pcs[$no]);

if (!empty($id[$no])){ //just process the checked pcs

$sql= mysql_query("select * from product_order where id='$id[$no]'") or die(mysql_error());
$row = mysql_fetch_array($sql);
$query = mysql_query("insert into product_checkout set id='$row[id]', name='$row[name]', price='$row[price]', pcs='$pcs[$no]'") or die(mysql_error());
}
}

?>


I was try and modified that code, but the column pcs from product_checkout always insert from the first loop (function "for" loop), event the checkbox unchecked...


what variable must im insert to column "pcs" on product_checkout table if i want just the checked only value...


some one help me please, im so confused...tq





Android Overflow Menu Checkbox Color

Is there a way to change the color of the checkbox in an android overflow menu.


My Current Checkbox is this:



<item android:title="Completed"
android:checked="false"
android:checkable="true"
android:id="@+id/completed"
>

</item>