I have a problem now, filtering is not working in the grid. and I don’t really see why. it should work. if I use the same as I used in this thread, there is ajax loading, in firebug request seems OK, but no filtering happens, there is not even an error message, but if I change it back to textField (so, remove listDataEx), I got the following error message: in firebug there is a GET call in red for a second, and after that:
Fatal error: Call to a member function isAttributeRequired() on a non-object in
...\framework\web\helpers\CHtml.php on line 1237
I have searched for this error, and found this thread that seemed relevant but as I see I have assigned value to $model ($order).
controller:
public function actionCreateMultiple() {
$order = new Order('search');
$order ->unsetAttributes();
for ($i = 0; $i < 10; $i++) {
$orderProducts[$i] = new OrderProduct;
}
if (isset($_POST['OrderProducts'])) {
$valid = true;
foreach ($orderProducts as $i => $orderProduct) {
if (isset($_POST['OrdersProducts'][$i]['orderId'])) { // we only deal with rows checked
$orderProduct->attributes = $_POST['OrderProducts'][$i];
$orderProduct->productId = $_POST['OrderProducts'][0]['productId']; // I give all models' the productId of the one and only productId dropdown.
} else {
unset($orderProducts[$i]);
}
$valid = $ordersProducts->validate() && $valid;
}
if ($valid) {// all orderProducts are valid
// ...do something here
}
}
$this->render('createMultiple', array('order' => $order, 'orderProducts' => $orderProducts));
}
createMultiple.php:
<?php
$this->renderPartial('_formMultiple', array(
'product' => $product,
'orderProducts' => $orderProducts,
'buttons' => 'create'));
?>
form:
<div class="form">
<?php
$form = $this->beginWidget('GxActiveForm', array(
'id' => 'product-form',
'enableAjaxValidation' => false,
));
?>
<p class="note">
<?php echo Yii::t('app', 'Fields with'); ?> <span class="required">*</span> <?php echo Yii::t('app', 'are required'); ?>.
</p>
<?php
foreach ($orderProducts as $i => $orderProduct) {
echo $form->errorSummary($orderProduct);
}
?>
<div class="row">
<?php echo $form->labelEx($orderProduct, "[0]orderId"); ?>
<?php echo $form->dropDownList($orderProduct, "[0]orderId", GxHtml::listDataEx(Order::model()->findAllAttributes(null, true)), array('style' => 'width: auto', 'prompt' => '')); ?>
<?php echo $form->error($orderProduct, "[0]orderId"); ?>
</div><!-- row -->
<?php
$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'product-grid',
'type' => 'striped bordered condensed',
'dataProvider' => $product->search(),
'filter' => $product,
'template' => "{items}{pager}",
'columns' => array(
...
'Pos',
array(
'name' => 'Pos',
'filter' => GxHtml::listDataEx(Product::model()->findAllAttributes('Pos', false, array('order' => 'CAST(Pos AS SIGNED)')), 'Pos', 'Pos'),
array(
'class' => 'bootstrap.widgets.TbButtonColumn',
'htmlOptions' => array('style' => 'white-space: nowrap'),
),
),
));
echo GxHtml::submitButton(Yii::t('app', 'Save'));
$this->endWidget();
?>
</div>
model:
public function search() {
$criteria = new CDbCriteria;
...
$criteria->compare('Pos', $this->Pos, true);
...
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
What can be wrong?
remaining flaws:
-
validation errors are still on the top (I would like to make background color red for textField with error)
-
a good upgrade would be if checking the checkbox would fill the textfield with the value of an other attribute, but that’s js and I’m not at home in js (too).
Thanks
BR
c