[EXTENSION] multimodelform/jqrelcopy Solutions for clientside cloning
#162
Posted 04 May 2012 - 03:43 AM
i wanted to use jquery-tipsy to add some tooltips to the multimodel fields in my form, but it seems not work.
Does anyone try this?
#163
Posted 04 May 2012 - 04:35 AM
How do I add values so that every member that I'm creating has it? A date that I set in my php code rather than via UI would be an example. I thought the $masterValues array would be the place but it doesn't seem to work.
I also have the problem that when I try to create my form, it adds an extra instance of the member boxes and complains about validation. Any ideas what may cause that kind of behaviour, the additional box?
Is $masterValues the right place to but my values that members share? Like so:
$masterValues = array ('session_id'=>$model->id,
'user_id'=>$model->user_id,
'date'=>$model->date,
);If that is the case then I know I've messed up something else. Any suggestions?
Thanks
edit:
When I don't enter anything into the member form, it doesn't attempt to validate it and saves the group part. When I put in values that should validate, it doesn't accept them and creates and extra member box to fill in. I've tried to restart from scratch and somehow I've ended up with the same nonsense.
#164
Posted 04 May 2012 - 04:56 AM
if you take a look at the 'function save' , the attributes will be assigned before saving the detail model:
public static function save($model, &$validatedItems, &$deleteItems = array(), $masterValues = array(), $formData = null)
{
...
if (!empty($masterValues))
$item->setAttributes($masterValues, false);
...
}
'$item' is the detail model and 'setAttributes' with $safeOnly=false is used;
So you have to check the attributes of the detail model, if this doesn't work.
Try to debug through the code or do var_dump... etc. here.
Try this test release if you don't want to show the additional empty member box.
#165
Posted 04 May 2012 - 05:42 AM
The behaviour with the box makes more sense to me now (having one as default but no additions or subtractions on submit would imho be best but I have other problems
The $masterValues still don't work. They live in the controller and I don't need to handle them anywhere else, right? I'm very new to this so I don't want to start blaming other people on things not working.
I tried removing the "deleteMembers" from MultiModelForm::save, since it seems redundant in the never version and might mess with the parameters but that didn't help either.
So now I'm lost because I'm not even sure which parts are my fault. Do people not usually use the masterValues?
I'm doing my best to find out what's wrong:
The following line is what fails:
if( //validate detail before saving the master
MultiModelForm::validate($member,$validatedMembers,$deleteItems)
// && $model->save()
)It doesn't validate, because the fields that I want want to set via $masterValues are required. So what I did was take the $mastValue assignment out of the if clause and put it before the check occurs. Much to my surprise, this changes nothing.
This is my attempt:
$masterValues = array('session_id'=>$model->id,'date'=>1,'user_id'=>1);I'm beyond lost. I don't even know where to look for what is going wrong. I don't know if it's the extension or my screwed up code. I might try creating a new project just to confirm the extension does what I think it does...
#166
Posted 04 May 2012 - 06:39 AM
There the $masterValues are used to save the the foreignkey 'groupid' from the master model.
This must work, otherwise the whole demo-app will be useless.
Try to debug to check why the masterValues don't work in your application.
#167
Posted 04 May 2012 - 07:38 AM
I kept getting the validation message when I tried to submit and that validation happens before the $masterValues get assigned. In order to get it to work, I've had to take the relevant fields out of the rules array where they were required.
If I understand the example code correctly, it would fail if groupid were a required field in the relevant model?!?
This is how I understand it:
=> validating the $member
MultiModelForm::validate($member,$validatedMembers,$deleteItems)
only after that $masterValues gets assignedL
$masterValues = array('session_id'=>1,'user_id'=>1,'date'=>1);Hence when $member gets validated, it fails, if any of the fields that $masterValues fills, are required. Moving the $masterValues before the first validation doesn't work, I assume that's down to how the extension works.
Does that make sense?
I'm aware that in this case I'm setting the values so no need to validate them. However, there is another use of the same model where the input could come from the user. I guess I'm surprised at how this works.
#168
Posted 04 May 2012 - 07:50 AM
//----------- NEW (on validation error) -----------
public function initItems(&$validatedItems, &$deleteItems, $masterValues = array(), $formData = null)
{
if (isset($formData[$modelClass]['n__']))
{
foreach ($formData[$modelClass]['n__'] as $idx => $attributes)
{
$model = new $modelClass;
$model->scenario = 'newMultimodel' //<------- add this
$model->attributes = $attributes;
Now in the rules of your detail model you can use 'on'=>'newMultimodel' to distinguish between standard validation and validation in the multimodelform.
If this helps, I will add the scenario line.
#169
Posted 04 May 2012 - 08:16 AM
Cheers
I guess it would add flexibility and give people a choice as to how they want to deal with scenarios. I think it would be useful but you have to judge to what extent what I'm doing is just stupid
If you want me to test anything let me know. I may need a sample rule to really understand how it works though.
I think I can work with what I have now so if you're busy don't worry.
Thanks for your time!
#171
Posted 19 June 2012 - 05:14 PM
Th3 R00ST3R, on 06 April 2012 - 10:33 AM, said:
I don't think this is a MMF issue, but I didn't know where else to post this..
I have one last piece and I think my form will be complete. I want to put the multimodelform into a cJuiTabs.
When I put the widget into the tab, It doesn't put it in the tab, but above it.
Can someone point me in the right direction?
$this->widget('zii.widgets.jui.CJuiTabs', array(
'tabs'=>array('Standard 1'=>array($this->widget('ext.multimodelform.MultiModelForm',array(
'id' => 'id_perfreviewsub2', //the unique widget id
'formConfig' => $perfreviewsubFormConfig, //the form configuration array
'model' => $perfreviewsub, //instance of the form model
//if submitted not empty from the controller,
//the form will be rendered with validation errors
'validatedItems' => $validatedPerfReviewSub,
'tableView' => true,
//array of perfreviewsub instances loaded from db
'data' => $perfreviewsub->findAll(array(
'condition' => 'performancereviewid=:performancereviewid and standardid=:standardid',
'params' => array(':performancereviewid'=>$model->performancereviewid,':standardid'=>1,),
'order' => 'standardid, elementid ' ))
))),
),
// additional javascript options for the tabs plugin
'options'=>array(
'collapsible'=>false,
),
));
Thank you very much.
Maybe it's too late, but it may help someone... When you do the renderPartial you need to add a true in the end, indicating that the result must be returned instead of rendered...
Here its an example:
'Paso 4'=>$this->renderPartial('pasoCuatro',array('form'=>$form,'model'=>$model,'detalleVenta'=>$detalleVenta,'detallesValidos'=>$detallesValidos),true),
#172
Posted 20 June 2012 - 06:49 PM
I am using this extension and it's great.
Is possible to use jquery in detail model ?
Example;
In detail model (Detall Bill)
I have one input text (Item Code), after to input this field I need to show How many items are in stock model
Any ideas?
#173
Posted 27 June 2012 - 12:05 AM
This is a great extension.
Sorry for my english.
I get autocomplete to work. May be you will had it to the next version.
What i notice :
1- .autocomplete() won't apply on the clone input
2- .autocomplete() wont work unless the input field is added to the page
What i've done :
1- .autocomplete() won't apply on the clone input
1-1 add a new input with same id and name
1-2 remove old input
1-3 apply .autocomplete() on new input
public static function whenDoneAutoComplete($element, $idElement)
{
$options = isset($element['options']) ? $element['options'] : array();
if (isset($element['sourceUrl']))
$options['source'] = CHtml::normalizeUrl($element['sourceUrl']);
else
$options['source'] = $element['source'];
$jsOptions = CJavaScript::encode($options);
return "
var acID=this.attr('id');
if(acID.indexOf('".$idElement."')>=0)
{
var acName=this.attr('name');
this.after('<input id=\"'+acID+'\" name=\"'+acName+'\" type=\"text\">');
this.remove();
$('#'+acID).autocomplete(".$jsOptions.");
}
";
}
But for this to work we have to give the name of the attribute to be treated ($idElement). So by now it will only work with one autocomplete. Need to review in order to handle an array of attributes name.
2- .autocomplete() wont work unless the input field is added to the page
2-1 add a new js options (jsWhenDone)
2-2 change jquery.relcopy.yii.3.3.js to handle whenDone new option
$(parent).find(rel+':last').after(clone);
$(clone).find('[id]').each(function(){
funcWhenDone.call($(this));
});
At this step i ran into a strange issue. the autocomplete of the master template stop working after adding more copies although all the AC from copies work well.
To correct this i decided to use the master template only for cloning and change relcopy like this
/*if(!master.is(":visible"))
{
master.show();
mmfRecordCount++;
return;
}*/
...
$(parent).find(rel+':last').after(clone);
$(clone).show();
$(clone).find('[id]').each(function(){
funcWhenDone.call($(this));
});
Perhaps it isn't the best way to do it but it works great for me.
I also change mmf to handle composit PK but do it qickly to get it working. May have some issues on delete with simple PK.
Hope this helps.
see attached files for complete changes
Attached File(s)
-
multimodelform.zip (10.84K)
Number of downloads: 25
#174
Posted 12 July 2012 - 04:52 AM
Why is that?
Is anyone can help me?
Cheers.
#175
Posted 13 July 2012 - 02:40 AM
Apparently, it is currently not possible to put several detail elements (eg, a Group of Members and Missions). The problem is that the widget can not distinguish the two elements in the number of records (if you add a member and a mission to a group, the widget think there are two members and two missions).
Has someone a solution for this problem?
#176
Posted 16 July 2012 - 08:29 AM
I am having one issue, 'Remove' text is repeated as shown in attachment.
Can anyone please help?
double.png (5.08K)
Number of downloads: 26
#177
Posted 16 July 2012 - 08:59 AM
I have to investigate this.
At the moment you have to set 'hideCopyTemplate' => false, if you use the tableView.
#179
Posted 23 July 2012 - 04:11 AM
When i load datas, i want that only some values appears for the user, in function of another field value.
This is partof my form:
<?php
$model3 = RelStudentSemester::model()->findAll(array('condition'=>"group_id = " . $model->group_id, 'order' => 'student_lastname, student_firstname'));
$data3 = array();
foreach ($model3 as $models){
if($models->resit == 2)
{
$data3[$models->student_id] = array(2=>'Rattrapage');
}
elseif($models->resit == 1)
{
$data3[$models->student_id] = array(1=>'Hors rattrapage');
}
elseif($models->resit == 0)
{
$data3[$models->student_id] = array(0=>'Non renseigné');
}
else
{
$data3[$models->student_id] = array(3=>'A renseigner', 1=>'Hors rattrapage', 2=> 'Rattrapage');
}
} ?>
...
<?php $relStudentSemesterFormConfig = array(
'elements'=>array(
...
'resit'=>array(
'type'=>'dropdownlist',
'items' => $data3,
),
...
When page load, i seee the correct value of the field (resit / rattrapage) but when i open the dropdownlist all values appears (see the attached file)...
Can someone help me with this?
#180
Posted 23 July 2012 - 04:12 AM
Attached File(s)
-
Capture d’écran 2012-07-23 à 10.59.12.png (121.72K)
Number of downloads: 32

Help













