Hi Jeremy,
The screenshot is attached.
pic1.png (63.1K)
Number of downloads: 14
Here is my _formDDetail
<tr>
<td>
<?php
$this->widget('EJuiAutoCompleteFkField', array(
'model' => $model,
'attribute' => "[$i]warehouseFk", //the FK field (from CJuiInputWidget)
// controller method to return the autoComplete data (from CJuiAutoComplete)
'sourceUrl' => Yii::app()->createUrl('/transaction/findWarehouse'),
// defaults to false. set 'true' to display the FK field with 'readonly' attribute.
// 'showFKField' => true,
// display size of the FK field. only matters if not hidden. defaults to 10
// 'FKFieldSize' => 15,
'relName' => 'warehouse', // the relation name defined above
'displayAttr' => 'warehouseName', // attribute or pseudo-attribute to display
// length of the AutoComplete/display field, defaults to 50
// 'autoCompleteLength' => 60,
// any attributes of CJuiAutoComplete and jQuery JUI AutoComplete widget may
// also be defined. read the code and docs for all options
'options' => array(
// number of characters that must be typed before
// autoCompleter returns a value, defaults to 2
// 'minLength' => 3,
),
));
?>
</td>
<td>
<?php echo $form->textField($model, "[$id]productFk", array('style' => 'width: 250px;')); ?>
</td>
<td>
<?php echo $form->textField($model, "[$id]batchNo", array('style' => 'width: 100px; text-align: center;')); ?>
</td>
<td>
<?php echo $form->textField($model, "[$id]quantity", array('style' => 'width: 100px; text-align: right;')); ?>
</td>
<td>
<?php echo CHtml::link(CHtml::image(Yii::app()->request->baseUrl . '/images/remove_ico.png'), '', array('class' => 'delete', 'onClick' => 'deleteDetail($(this))')); ?>
</td>
</tr>
and this is my controller that preloaded with 5 TransactionDetail
public function actionCreate() {
$model = new Transaction;
$model->date = date('Y-m-d');
$model->status = Category::ACTIVE;
$model->operatorFk = Yii::app()->user->id;
$details = array();
for ($i = 0; $i < 5; $i++) {
$details[] = new TransactionDetail;
}
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Transaction'], $_POST['TransactionDetail'])) {
$model->attributes = $_POST['Transaction'];
$valid = $model->validate();
$_POST['TransactionDetail'] = array_values($_POST['TransactionDetail']);
$details = array();
for ($i = 0; $i < count($_POST['TransactionDetail']); $i++) {
$details[] = new TransactionDetail;
}
foreach ($details as $i => $detail) {
if (isset($_POST['TransactionDetail'][$i]))
$detail->attributes = $_POST['TransactionDetail'][$i];
$valid = $detail->validate() && $valid;
}
if ($valid) {
$model->save();
foreach ($details as $i => $detail) {
$detail->transactionFk = $model->id;
$detail->save();
}
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array(
'model' => $model,
'details' => $details,
));
}
Also, I was wondering why the button [x] is not displayed properly now?
Cheers,
Daniel