Yii Framework Forum: [EXTENSION] multimodelform/jqrelcopy - Yii Framework Forum

Jump to content

  • (15 Pages)
  • +
  • « First
  • 3
  • 4
  • 5
  • 6
  • 7
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

[EXTENSION] multimodelform/jqrelcopy Solutions for clientside cloning Rate Topic: ***** 4 Votes

#81 User is offline   Joblo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 685
  • Joined: 12-September 10
  • Location:Austria

Posted 25 November 2011 - 04:29 AM

The addlink is rendered by MultiModelRenderForm.getAddLink().

Take a look at the html source and create a css to move this item around.
0

#82 User is offline   Mr D 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 217
  • Joined: 18-May 11

Posted 27 November 2011 - 10:52 PM

I want to ask something

I have two input, the first is param_type, and the second is param_value ..
I want to make when I set the param type = 0, then param_value = textField
if param type = 1, then param_value = dropDown ..

is it possible to do this? :)
Boss: "We found a bug in your code!"
Programmer: "That's no bug, that's just an undocumented feature!"
0

#83 User is offline   IRCSASW 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 01-September 11
  • Location:Cancún, México.

Posted 28 November 2011 - 09:40 PM

Hello,

How I can do to add items to the calculations made ​​in the fields of the parent table.

Thanks,

Attached File(s)


Arturo Ramos
www.ircsasoftware.com.mx
Cancún, México
0

#84 User is offline   Joblo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 685
  • Joined: 12-September 10
  • Location:Austria

Posted 29 November 2011 - 05:35 AM

Mr D: Sorry, I don't see a change for this :-(

IRCSASW:
Should be possible with js/jQuery.
Try to set the 'onChange' of your inputs and add js-code to the property 'jsAfterClone' of the multimodelform.
I would try to add code direct in the js-script 'jquery.relcopy.yii.1.0.js' first and afterwards when it works put the code outside to the 'jsAfterClone'.


You both should know:
At the clientside multimodelform does only clone a collection of form elements
and increments the id of each element by an integer so that the form values are posted as an array on submit.
Nothing more happens.

So if you need complex features you have to work with javascript before/after cloning the elements and you have to understand the code from 'jquery.relcopy.yii.1.0.js' how the cloning works.
0

#85 User is offline   IRCSASW 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 01-September 11
  • Location:Cancún, México.

Posted 29 November 2011 - 12:14 PM

View PostJoblo, on 29 November 2011 - 05:35 AM, said:

Mr D: Sorry, I don't see a change for this :-(

IRCSASW:
Should be possible with js/jQuery.
Try to set the 'onChange' of your inputs and add js-code to the property 'jsAfterClone' of the multimodelform.
I would try to add code direct in the js-script 'jquery.relcopy.yii.1.0.js' first and afterwards when it works put the code outside to the 'jsAfterClone'.


You both should know:
At the clientside multimodelform does only clone a collection of form elements
and increments the id of each element by an integer so that the form values are posted as an array on submit.
Nothing more happens.

So if you need complex features you have to work with javascript before/after cloning the elements and you have to understand the code from 'jquery.relcopy.yii.1.0.js' how the cloning works.


Thanks Joblo, I'll work on this. Greetings.
Arturo Ramos
www.ircsasoftware.com.mx
Cancún, México
0

#86 User is offline   Joblo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 685
  • Joined: 12-September 10
  • Location:Austria

Posted 08 December 2011 - 08:34 AM

LiuXuan: Comment IDENTITY_INSERT issue when adding new member


multimodelform renders all db-fields into the form. If elements are not configured in the formConfig, the fields are rendered as type='hidden'.
This is necessary because there is no 'loadmodel' before update, so all record values has to be submitted from the form.
So an empty PK autoinc fieldvalue is submitted too.

But on save, the extension uses the Yii $model->save() method.
AFAIK, this method handles the 'autoincrement', so the autoinc attribute should not be submitted to the db.

Otherwise you can use the models 'beforeSave' to remove the autoinc attribute or set it to NULL.
Maybe this is an issue of the difference of an empty fieldvalue '' or NULL.


multimodelform should not output the fields which are not configured as elements in the formconfig.
But there is an issue so the labels of hidden fields are rendered in the table header too.

You can fix this in line 832 of MultiModelForm.php version 2.2.1

public function renderTableHeader()
	{
		$cells = '';

		foreach($this->getElements() as $element)
			if ($element->visible  && !$element->type == 'hidden') //<--- add check for hidden type too
			{
				$text = empty($element->label) ? '&nbsp;' : $element->label;
				$options = array();




Im currently working on version 3 (adding 'sortable' feature).
Please let me know more about your issues.
0

#87 User is offline   IRCSASW 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 01-September 11
  • Location:Cancún, México.

Posted 08 December 2011 - 02:12 PM

View PostJoblo, on 08 December 2011 - 08:34 AM, said:

LiuXuan: Comment IDENTITY_INSERT issue when adding new member


multimodelform renders all db-fields into the form. If elements are not configured in the formConfig, the fields are rendered as type='hidden'.
This is necessary because there is no 'loadmodel' before update, so all record values has to be submitted from the form.
So an empty PK autoinc fieldvalue is submitted too.

But on save, the extension uses the Yii $model->save() method.
AFAIK, this method handles the 'autoincrement', so the autoinc attribute should not be submitted to the db.

Otherwise you can use the models 'beforeSave' to remove the autoinc attribute or set it to NULL.
Maybe this is an issue of the difference of an empty fieldvalue '' or NULL.


multimodelform should not output the fields which are not configured as elements in the formconfig.
But there is an issue so the labels of hidden fields are rendered in the table header too.

You can fix this in line 832 of MultiModelForm.php version 2.2.1

public function renderTableHeader()
	{
		$cells = '';

		foreach($this->getElements() as $element)
			if ($element->visible  && !$element->type == 'hidden') //<--- add check for hidden type too
			{
				$text = empty($element->label) ? '&nbsp;' : $element->label;
				$options = array();




Im currently working on version 3 (adding 'sortable' feature).
Please let me know more about your issues.


I think it's best to do this by defining the form members:
$memberFormConfig = array(
   'elements'=>array(
      'firstname'=>array(
         'type'=>'text',
         'maxlength'=>40,
      ),
      'lastname'=>array(
         'type'=>'text',
         'maxlength'=>40,
      ),
      'membersince'=>array(
         'type'=>'dropdownlist',
         //it is important to add an empty item because of new records
         'items'=>array(''=>'-',2009=>2009,2010=>2010,2011=>2011,),
      ),
   
      // Invisible
      'id'=>array(
         'type'=>'hidden',
         'visible'=>false,  // not seen in the table
      ),
      'active'=>array(
         'type'=>'hidden',
         'visible'=>false,  // not seen in the table
      ),
));


In this way the labels 'id' and 'active' not shown in the table and the fields are sent with the form.

Is that correct? This worked for me. <_<

Regards.
Arturo Ramos
www.ircsasoftware.com.mx
Cancún, México
0

#88 User is offline   Joblo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 685
  • Joined: 12-September 10
  • Location:Austria

Posted 08 December 2011 - 03:46 PM

Yes this is ok.

In the last release I didn't pay attention to the 'visible' attribute.
I thought this is false for hidden elements but is always true for all FormInputElements.

I will change this behavior in the upcoming release, so you don't need to add the invisible elements to the formConfig.
0

#89 User is offline   LiuXuan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 24-April 11
  • Location:Beijing

Posted 08 December 2011 - 09:28 PM

View PostJoblo, on 08 December 2011 - 08:34 AM, said:

LiuXuan: Comment IDENTITY_INSERT issue when adding new member


multimodelform renders all db-fields into the form. If elements are not configured in the formConfig, the fields are rendered as type='hidden'.
This is necessary because there is no 'loadmodel' before update, so all record values has to be submitted from the form.
So an empty PK autoinc fieldvalue is submitted too.

But on save, the extension uses the Yii $model->save() method.
AFAIK, this method handles the 'autoincrement', so the autoinc attribute should not be submitted to the db.

Otherwise you can use the models 'beforeSave' to remove the autoinc attribute or set it to NULL.
Maybe this is an issue of the difference of an empty fieldvalue '' or NULL.


multimodelform should not output the fields which are not configured as elements in the formconfig.
But there is an issue so the labels of hidden fields are rendered in the table header too.

You can fix this in line 832 of MultiModelForm.php version 2.2.1

public function renderTableHeader()
	{
		$cells = '';

		foreach($this->getElements() as $element)
			if ($element->visible  && !$element->type == 'hidden') //<--- add check for hidden type too
			{
				$text = empty($element->label) ? '&nbsp;' : $element->label;
				$options = array();




Im currently working on version 3 (adding 'sortable' feature).
Please let me know more about your issues.

Thank you Joblo, for issue 2, I add the code as you suggest, it works! I am so happy.
for the issue 1, insert identity, I solved by add following code in the save function, I am a newbie learning Yii, I feel it may be not a good way , can you help me on how to do it better?
public static function save($model,&$validatedItems, &$deleteItems=array(), $masterValues = array() ,$formData = null)
	{
		//validate if empty: means no validation has been done
		$doValidate = empty($validatedItems) && empty($deleteItems);

		if ($doValidate)
		{
			//validate and assign $masterValues
			if (!self::validate($model, $validatedItems, $deleteItems, $masterValues , $formData))
				return false;
		}

		if (!empty($validatedItems))
			foreach ($validatedItems as $item)
			{
				if (!$doValidate)  //assign $masterValues
				{
					if (!empty($masterValues))
						$item->setAttributes($masterValues,false);
				}
                      if( empty($item['id']) ) unset($item['id']);   //<-this is added by me,how can I do it better?
				if (!$item->save())
					return false;
			}
           //$deleteItems = array of primary keys to delete
		if (!empty($deleteItems))...        

Maybe there's a way to know $item['pkcolumnname'] instead of my hard coding?
Thank you again for helping. :)
0

#90 User is offline   urgent 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 20-July 11

Posted 14 December 2011 - 08:59 PM

Is there any way to append html next to a row element? I'm would like to add a hyperlink next to a drop down.

In the jqrelcopy documentation there is:

//Additional HTML to attach at the end of each copy.
'append'=>CHtml::tag('span',array('class'=>'hint'),'You can remove this line'),

But I tried adding this in my FormConfig array and it didn't work.

There's always jQuery's after(), and I suppose I can create a widget for a dropdown hyperlink combination, but I would be surprised if there append is not built into multimodelform. Thanks.
0

#91 User is offline   Joblo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 685
  • Joined: 12-September 10
  • Location:Austria

Posted 15 December 2011 - 06:35 AM

If you want to pass a property value to jqrelcopy, you have to use 'options' of the widget.

  $this->widget('ext.jqrelcopy.JQRelcopy',array( //or multimodelform 
 ...
  'options'=>array('append'=>CHtml::tag('span',array('class'=>'hint')),
   ...


If you want to add additional html to the form you can add strings as elements in the formConfig


$memberFormConfig = array(
      'elements'=>array(
        'firstname'=>array(
            'type'=>'text',
            'maxlength'=>40,
        ),

       '<hr/>', //<--add html-code as string to the elements array

       CHtml::tag('span',array('class'=>'hint')), //<-- string
        ...
        
    ));


0

#92 User is offline   urgent 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 20-July 11

Posted 15 December 2011 - 11:32 AM

Will the first code append to all elements?

Will the 2nd set of code add another <div class="row">
0

#93 User is offline   aatlikan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 25-November 11

Posted 15 December 2011 - 11:58 AM

how can I set detail form value?

if(isset($_POST['Master'],$_POST['Detail']))
    {
        $model->attributes=$_POST['Master'];
        $model->price=....(ok its  work)
 if( //validate detail before saving the master
            MultiModelForm::validate($detail,$validatedDetail,$deleteItems) &&
            $model->save()
           )
           {
            
            
            
             //the value for the foreign key 'groupid'
             $masterValues = array ('ID'=>$model->ID);
 
                $detail->attributes=$_POST['Detail'];
                $detail->color='Green';

.....
}


it doesnt work!
0

#94 User is offline   Joblo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 685
  • Joined: 12-September 10
  • Location:Austria

Posted 15 December 2011 - 06:03 PM

urgent: quick response without testing - please try yourself

- 'append' will add code after cloning a fieldset/group

- the 2nd set of code add another <div class="row"> because every form element is wrapped into the div
0

#95 User is offline   Joblo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 685
  • Joined: 12-September 10
  • Location:Austria

Posted 15 December 2011 - 06:11 PM

aatlikan: please take a look at the source code and see what happens on validate / save

The '$detail' model will never been saved, its only for analysing the model structure/attributes.

In this extension you don't have a single detail model, because of clientside cloning.
So you have an array of detailmodels '$validatedItems' (the second parameter).
After calling validate, this array is populated with the submitted data of all detail models.
You can loop through this array and change the detail-models after calling MultiModelForm::validate and before calling MultiModelForm::save.
0

#96 User is offline   urgent 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 20-July 11

Posted 15 December 2011 - 07:54 PM

View PostJoblo, on 15 December 2011 - 06:03 PM, said:

urgent: quick response without testing - please try yourself

- 'append' will add code after cloning a fieldset/group

- the 2nd set of code add another <div class="row"> because every form element is wrapped into the div


I tried the 2nd set of code but could not get it to appear. I did not try the 1st because I do not have a call to the JQRelcopy widget in my code. I was able to append a link next to a select box using jQuery's after().

One issue with this is it appears Add Item will just copy the code from the first form element. I have code to add an update link when a record is selected in a drop down, and this gets copied over even when the select box is set to the empty record/Please Select value.

Do you know of an easier approach? I'm just looking for code to do:

<select> <a>Add</a> (if selected) <a>update</a>

Thanks.
0

#97 User is offline   urgent 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 20-July 11

Posted 16 December 2011 - 12:38 PM

View Posturgent, on 15 December 2011 - 07:54 PM, said:

I tried the 2nd set of code but could not get it to appear. I did not try the 1st because I do not have a call to the JQRelcopy widget in my code. I was able to append a link next to a select box using jQuery's after().

One issue with this is it appears Add Item will just copy the code from the first form element. I have code to add an update link when a record is selected in a drop down, and this gets copied over even when the select box is set to the empty record/Please Select value.

Do you know of an easier approach? I'm just looking for code to do:

<select> <a>Add</a> (if selected) <a>update</a>

Thanks.


I got it fixed using jsAfterClone to hide the update link
0

#98 User is offline   urgent 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 20-July 11

Posted 18 December 2011 - 12:22 PM

Hello again:
When I submit the form without validation errors it acts as normal. However if there are validation errors on the page I get the yii error page with this error. I checked $formData[$modelClass] and its empty after validation. Is this because the name of the form changes with validation errors? After validation error it adds [n__] to the name before the [0]. Here is the error:

Invalid argument supplied for foreach()

(REMOVED)/protected/extensions/multimodelform/MultiModelForm.php(439)

427 foreach ($allExistingPk as $idx => $delPks)
428 $deleteItems[] = $delPks;
429
430 // remove handled formdata pk__
431 unset($formData[$modelClass]['pk__']);
432
433 //----------- ADDED by jQuery -----------
434
435 // use the first item as reference
436 print_r($formData[$modelClass]); //I added this line to check the variable which is empty array
437 $refAttribute = key($formData[$modelClass]);
438 $refArray = array_shift($formData[$modelClass]);
439 foreach($refArray as $idx => $value)
440 {
441 // check continue if all values are empty
442 if (empty($value))
443 {
444 $allEmpty = true;
445 foreach ($formData[$modelClass] as $attrKey => $values)
446 {
447 if (is_array($values[$idx])) //bugfix v2.1.1 have to check empty array items too
448 {
449 $isEmpty = true;
450 foreach ($formData[$modelClass][$attrKey] as $item)
451 {

Stack Trace
#0

/home/cam3/public_html/root/links/protected/extensions/multimodelform/MultiModelForm.php(329): MultiModelForm->initItems(array(TransactionsDetails), array(), array(), null)

324 $widget = new MultiModelForm;
325 $widget->model = $model;
326
327 $widget->checkModel();
328
329 if (!$widget->initItems($validatedItems, $deleteItems, $masterValues, $formData))
330 return false; //at least one item is not valid
331 else
332 return true;
333 }
334
0

#99 User is offline   Joblo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 685
  • Joined: 12-September 10
  • Location:Austria

Posted 18 December 2011 - 01:27 PM

Yes in 'error' mode, the cloned elements by jquery from the previous screen are rendered as [n__].

But there should always a 'copyTemplate' with the empty inputs be added as last item (see procedure run()).
The empty item should be added independent of the update- or errormode.
Therefore the $formData[$modelClass] should never be empty.
0

#100 User is offline   urgent 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 20-July 11

Posted 18 December 2011 - 10:55 PM

Hello:
What was going on was I followed this post to remove the extra record with an error:

http://www.yiiframew...252#entry102252

What I did to fix the error when only error box are submitted is to copy the n__ values to the post array at the beginning of initItems like it was a normal submit. I had some issues with extra forms being shown until I added the unset n_

//allow error forms to submit data
        $formDataSet=false;
            foreach(array_keys($_POST[$modelClass]) as $modClassArrKey){
                if($modClassArrKey!= 'n__' && $modClassArrKey!='pk__' && $modClassArrKey!='u__'){
                    $formDataSet=true;
                }
            }
            if(!$formDataSet){
                foreach(array_keys($_POST[$modelClass]['n__']) as $nRows){
                    foreach(array_keys($_POST[$modelClass]['n__'][$nRows]) as $nFields){
                        $_POST[$modelClass][$nFields][$nRows]=$_POST[$modelClass]['n__'][$nRows][$nFields];
                    }
                }
                unset($_POST[$modelClass]['n__']);
            }

0

Share this topic:


  • (15 Pages)
  • +
  • « First
  • 3
  • 4
  • 5
  • 6
  • 7
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users