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

Jump to content

  • (14 Pages)
  • +
  • « First
  • 6
  • 7
  • 8
  • 9
  • 10
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

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

#141 User is offline   Sampa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 173
  • Joined: 18-December 11
  • Location:Stockholm,Sweden

Posted 09 March 2012 - 07:53 PM

Hi, This is cool stuff.

I have tried to use a text-editor for one field,


EDIT*** Sorry I was a tired retard, I tried with type=>textArea instead of type=>textarea
All fine now :P
0

#142 User is offline   Joblo 

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

Posted 10 March 2012 - 03:55 PM

Loren:

Thanks for your example.

On debugging / var_dumping through the code I have detected, that the issue with the checkboxes is not as easy I thought first :-(

The problem is to handle the count of the submitted values of the checkboxes.
For one cloned checkbox there can exists one (submitted by the hidden yii-attribute if not checked) or two values (hidden yii-attribute and the cloned checkbox) in the submitted attributes array.

So the count of the submitted values from cloned checkboxes never matches the count of the other attributes and the multimodelform::initItems code is wrong for this :-(

I need an idea first, how to handle checkboxes ... in js or the initItems code.
0

#143 User is offline   yankii 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 01-March 12

Posted 11 March 2012 - 04:33 AM

I tested this with CFormModel and it can work with it but needs some modifications in your form and MultiModelForm.php. The CFormModel doesn't initially have or inherit the primaryKey property and method so those need to be added to the form that is used. In addition the MultiModelForm needs to be modified to be able to read it...

public function getPrimaryKey($model)
{
$result = array();

if ($model instanceof CActiveRecord)
{
$pkValue = $model->primaryKey;
if (!empty($pkValue))
{
$pkName = $model->primaryKey();
if (empty($pkName))
$pkName = $model->tableSchema->primaryKey;

$result = array($pkName => $pkValue);
}
}
else if($model instanceof CFormModel && method_exists($model, 'primaryKey') && $model->primaryKey)
{
$pkValue = $model->primaryKey;
if (!empty($pkValue))
{
$pkName = $model->primaryKey();
if (!empty($pkName))
$result = array($pkName => $pkValue);
}
}

else // when working with EMongoDocument
if (method_exists($model, 'primaryKey'))
{
$pkName = $model->primaryKey();
$pkValue = $model->$pkName;
if (empty($pkValue))
$result = array($pkName => $pkValue);
}

return $result;
}

Also, maybe it was mentioned somewhere but it might be worth emphasizing that the $validatedItems is an array of models used with multimodel form and the $deleteItems is an array of primary keys.
0

#144 User is offline   Sampa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 173
  • Joined: 18-December 11
  • Location:Stockholm,Sweden

Posted 11 March 2012 - 03:08 PM

Joblo! I had ton of problems getting the cloning to work with my wysiwyg editor, multiple instances but all toolbars sent
input etc to the first instance (thats there on load). And it was impossible to write anything in the "clones".

My solution was: I took the js code rendered by my editor widget and put it in a seperate file.

I created a tiny action in my controller, that only made a renderPartial on my seperate file.

I then used 'jsAfterClone'=>'$("#foo").load("/howto/eltre")', in the multimodelconfiguration.
and tada, it worked like a charm.
0

#145 User is offline   Sampa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 173
  • Joined: 18-December 11
  • Location:Stockholm,Sweden

Posted 11 March 2012 - 05:21 PM

Is it possible to just skip having the first item visible? so that nothing is shown until you press "add item" and a cloned element appears?
0

#146 User is offline   Loren 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 29-December 10
  • Location:SC, USA

Posted 11 March 2012 - 08:19 PM

View PostJoblo, on 10 March 2012 - 03:55 PM, said:

Loren:

Thanks for your example.

On debugging / var_dumping through the code I have detected, that the issue with the checkboxes is not as easy I thought first :-(

The problem is to handle the count of the submitted values of the checkboxes.
For one cloned checkbox there can exists one (submitted by the hidden yii-attribute if not checked) or two values (hidden yii-attribute and the cloned checkbox) in the submitted attributes array.

So the count of the submitted values from cloned checkboxes never matches the count of the other attributes and the multimodelform::initItems code is wrong for this :-(

I need an idea first, how to handle checkboxes ... in js or the initItems code.

Yeah, that is what I was looking at.
The only way I could figure out to fix it would be to assign array indexes (just like you do for when things are already set) to everything. I think that would require several new pieces in your serverside and clientside JS.

Here is my idea:
1. Serverside: Use the existing count variable for the existing rows but increment it by 1 and set that is the new row
2. Serverside: Echo a new variable for JS called nextRowCount (for it to use as the index of the next row)
3. Clientside: Have the JS grab the nextRowCount when inserting new rows and increment it after each insert

Make since? It actually might not be that hard. It just depends how much effort it will take to make the global serverside and clientside variables.
You could even use a hidden form field for the client side one. (I would, however, make you JS code fallback to its normal way of not specifying an index if the field for next row index is missing though. That way it will be reverse compatible for people who are just using the JS portion.)
0

#147 User is offline   Sampa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 173
  • Joined: 18-December 11
  • Location:Stockholm,Sweden

Posted 12 March 2012 - 06:48 AM

Hm, If i add related records when I update a main-model record the related records are saved properly,
but If I use the same form to add related records when I create a new main-model record only the main record is saved.

I've tried to look for diffrences but I cant find whats causing this.

here is my controller actions and views:
http://pastebin.com/qkFHdwxw
0

#148 User is offline   acorncom 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 99
  • Joined: 25-February 11
  • Location:CO, USA

Posted 13 March 2012 - 12:35 PM

View PostJoblo, on 10 March 2012 - 03:55 PM, said:

Loren:

Thanks for your example.

On debugging / var_dumping through the code I have detected, that the issue with the checkboxes is not as easy I thought first :-(

The problem is to handle the count of the submitted values of the checkboxes.
For one cloned checkbox there can exists one (submitted by the hidden yii-attribute if not checked) or two values (hidden yii-attribute and the cloned checkbox) in the submitted attributes array.

So the count of the submitted values from cloned checkboxes never matches the count of the other attributes and the multimodelform::initItems code is wrong for this :-(

I need an idea first, how to handle checkboxes ... in js or the initItems code.


Joblo, would it make sense to put the multimodelform code up on Github and then use the issue tracker to discuss this further? I've been looking at the checkbox issue myself for a project I'm working on. I'd be happy to help with it as well. Seems like the discussion of this issue might get lost in the other posts on this thread though ... I'm happy to post your latest multimodelform extension up if that would be helpful, but thought you might want to retain ownership ...

Let me know.
0

#149 User is offline   acorncom 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 99
  • Joined: 25-February 11
  • Location:CO, USA

Posted 13 March 2012 - 12:48 PM

View PostLoren, on 11 March 2012 - 08:19 PM, said:

Yeah, that is what I was looking at.
The only way I could figure out to fix it would be to assign array indexes (just like you do for when things are already set) to everything. I think that would require several new pieces in your serverside and clientside JS.

Here is my idea:
1. Serverside: Use the existing count variable for the existing rows but increment it by 1 and set that is the new row
2. Serverside: Echo a new variable for JS called nextRowCount (for it to use as the index of the next row)
3. Clientside: Have the JS grab the nextRowCount when inserting new rows and increment it after each insert

Make since? It actually might not be that hard. It just depends how much effort it will take to make the global serverside and clientside variables.
You could even use a hidden form field for the client side one. (I would, however, make you JS code fallback to its normal way of not specifying an index if the field for next row index is missing though. That way it will be reverse compatible for people who are just using the JS portion.)


What if we were to shift to something more like Yii does for handling input data? I realize this could break backwards compatibility badly ... (could we have a flag for the widget that defines how this gets handled?)

Yii does things like this:
<input name="Contact[35][Phone]" id="Contact_35_Phone" type="text">


where this JS handles it like this:
<input name="Contact[Phone][]" id="Contact_Phone" type="text">


Would moving to the Yii system allow you to let Yii handle the attributes better for these types of inputs too? Just thinking out loud.
0

#150 User is offline   Joblo 

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

Posted 13 March 2012 - 01:04 PM

I would be glad to have co-maintainers (loren, fr0d0z ...) who understand the code of this extension.

I really don't have the time to investigate and fix all issues posted here. It needs time and ideas to support more form input elements ...

So it's a good idea to put the latetest code on Github.
If you want you can do this, because I have never used Github before.
0

#151 User is offline   acorncom 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 99
  • Joined: 25-February 11
  • Location:CO, USA

Posted 13 March 2012 - 03:38 PM

Ok, code is up on Github:
https://github.com/a.../multimodelform

Joblo, it's really easy. If you sign up for an account, I'll add you as a collaborator on the code. And then we can take this issue over to Github's Issue Tracker.
0

#152 User is offline   Sampa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 173
  • Joined: 18-December 11
  • Location:Stockholm,Sweden

Posted 14 March 2012 - 12:01 PM

I've really tried to make texteditors to work for the textareas, My last solution did not work as I thought it did.

Somehow it seems to appear when adding a third element. I've walked thrue your code but 1200 rows and to be honest my knowledge is limited on how widgets work. Any thoughts on this? Which function and where should I try to modify?
What is the availeble variables?
0

#153 User is offline   danzs 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 29-March 12

Posted 29 March 2012 - 05:01 AM

Hi Everyone!

first off, thank you very much for this awesome extension. I'm very new to yii and I would like to ask for anyone's help on how I could solve something I am not sure of with multimodelform:

I am currently working on a billing system. So basically there is a TOTAL AMOUNT DUE field in form and the value of this fied should change as you enter items for the billing items. I have the following fields for items:

quantity, amount, discount and total

As you enter quantity and amount the total box should be auto filled, and the sum of the value of the total boxes will be the value for TOTAL AMOUNT DUE field

How can i achieve this with multimodelform and yii. Thank you very much.

--------------
UPDATE:
I was able to do the computations already thru onchange event, the only problem is the javascript is not being run if there is just one row of fields for the items.. it will only start computing once I added a new row. Please help... thank you very much.
0

#154 User is offline   Prakhar Birla 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 04-April 12

Posted 04 April 2012 - 07:51 AM

Hi,

I'm facing some issues after using the MultiModelForm. In the base form, i have many MultiModelForm's rendering.
Problem:
The form values for MultiModelForm's fields are not changing if the validation is failed. After debugging I have found the bug.

I am using MultiModelForm to render forms of different datatype for the same field. So the name of these attributes across multiple models is same due to which validation is failing.

If it's not clear please ask again.
0

#155 User is offline   Th3 R00ST3R 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 07-February 12

Posted 06 April 2012 - 10:33 AM

Hi,
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.
0

#156 User is offline   Andrey_ 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 13-January 12

Posted 28 April 2012 - 05:59 AM

Hello all
I can't figure out how to solve this problem:

View PostSampa, on 11 March 2012 - 05:21 PM, said:

Is it possible to just skip having the first item visible? so that nothing is shown until you press "add item" and a cloned element appears?

0

#157 User is offline   Joblo 

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

Posted 28 April 2012 - 08:35 PM

It's not so easy ... needs changes to the php and js-script.
But I did it, because maybe this feature is useful.

Please try the attached new release (new property $hideCopyTemplate=true by default)
and let me know, if it works for you.

Don't forget to delete the published assets.

[EDIT] removed the attachment, see comment below
0

#158 User is offline   Andrey_ 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 13-January 12

Posted 28 April 2012 - 10:35 PM

Unfortunately, this does not work for me. When I click "Add Item" nothing happens.
0

#159 User is offline   Joblo 

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

Posted 29 April 2012 - 12:17 PM

Would be nice, if you can submit more information.

For me with the demo-app this test-release works.

- what does the js-console tell, any error-message?
- are you sure, that you work with the new js-script (cache, deleted published asset)?
- did you test with the demo-app?
....
0

#160 User is offline   Joblo 

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

Posted 29 April 2012 - 04:16 PM

Sorry, the zip-file above contains the wrong js-asset file.

I did the changes only in my published assets folder and forgot to change the extension js-file ... :-(

Here is the new one.

[EDIT: Removed attached test code. It's the official 3.2 release now]
0

Share this topic:


  • (14 Pages)
  • +
  • « First
  • 6
  • 7
  • 8
  • 9
  • 10
  • 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