logo
Ask your Symfony questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$10
Updating Specific Partials when they are within embedded form(s)

I am rendering a component inside an embedded form: here's the breakdown.
There are multiple images to a gallery page. Each image object has a component/partial that allows you to add tag(s) to that image.

So it looks like this
GalleryPage
- Art
--_tagwidget (partial) - this partial is fed information specific from the Art embedded form its attached to

I got that to work without problem...BUT when I try to render/refresh the partial (after you add a tag) it updates EVERY iteration of that partial on the page

Forinstance:
If there are 3 Art objects it updates ALL of the _tagwidget embedded into each one with the results of the query. I want to ONLY update the widget associated with that specific component/partial...does that make sense.

that way it doesnt update EVERY tagwidget partial on the page - if there was a way to do
<?php include_partial('managepage/tagwidget(1)', array('sidemenu' => $sidemenu)) ?>
<?php include_partial('managepage/tagwidget(2)', array('sidemenu' => $sidemenu)) ?>

etc... than I could target the partial directly, but I dont really see a way to approach this...maybe I am looking at it wrong?

Basically = Whats the best way to approach this when there are multiple iterations of the same partial on one page but just need to update ONE of them based on an action


UPDATE//////////Some code
Inside the gallery page I include the partial that lists all of the embedded forms
<?php include_partial('managepage/list', array('formgallery' => $formgallery,'form' => $form,'findid' => $findid,'siteid' => $siteid )) ?>


Inside the "_list" partial
I iterate through all embedded art "form" objects


Inside that loop I get a component that uses the object from the associated id of that embedded form within the loop
<?php foreach ($formgallery['Art'] as $i => $pForm): 

<?php include_component('taggableComplete','tagWidget', array('object' => Master::getArtObject($anchor['id']))) ?>
<?php endforeach; ?>


Then I use js to submit the tag request in ajax

<input type="button" class="a-btn icon a-submit a-add" value="Add" onClick ="addTag('<?php echo get_class($object->getRawValue())?>','<?php echo $object->id; ?>')" />

function addTag($class, $id) {

$target = $class+$id;
$targetcontent = $("input."+$target).val();

$.post('<?php echo url_for("@default?module=managepage&action=addarttag") ?>', { tags:$targetcontent, object_id:$id});


};


THE PROBLEM
return $this->renderComponent('taggableComplete', 'tagWidget', array('object' => $object)); 


This happens on success of adding a tag...BUT it renders EVERY tagWidget on the page with the results of that specific query...which replaces every embedded tag form with the results from that specific partial/component. I need a way to target JUST the partial/component thats being updated (even though they are technically all the same partial - the original include_component happens in the scope of a loop which is how I am able to render diff data for each one on page load - the widget obv also lists current tags)

I could prob re render the whole list partial that houses this data...but if there are 100 image objects on the page, thats a lot of queries I'd have to run every time you add even one tag (to just one Art item)

Hope that makes sense - im open to looking at this diff from a structure perspective, Im just not seeing the right solution.

This question has been answered.

leftrock | 11/02/11 at 1:06pm Edit

Previous versions of this question: 11/02/11 at 1:37pm

(10) Responses

See a threaded view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    11/02/11
    1:16pm
    Ben says:

    could you post some code? are you updating them with JavaScript, or reloading the page?

  • avatar
    Last edited:
    11/02/11
    1:22pm
    Luis Cordova says:

    working on your solution

  • avatar
    Last edited:
    11/02/11
    5:41pm
    Milena Dimitrova says:

    You cannot do this:

    <?php include_partial('managepage/tagwidget(1)', array('sidemenu' => $sidemenu)) ?>
    <?php include_partial('managepage/tagwidget(2)', array('sidemenu' => $sidemenu)) ?>

    but you can pass the object (or, if you prefer, just the object ID) to the partial as an argument and this will make every partial unique.

    Also you can wrap each of the partials in an individual div with a unique ID:
    <?php foreach ($objects as $object): ?>
    <div id="tagwidget<?php echo $object->getId(); ?>">
    <?php include_component('yourmodule' , 'tagwidget', array('object' => $object )) ?>
    </div>
    <?php endforeach ?>


    Having these unique div IDs (such as tagwidget1, tagwidget2 etc) your Javascript function will be able to update exactly what you need - the last saved widget area:

    function  addTag($class, $id) 
    {
    $target = $class+$id;
    $targetcontent = $("#"+$target).val();
    var params = {};
    params['tags']=$("#"+$target).val();
    params['object_id']=$id;
    var ajax = new $.post('<?php echo url_for("@default?module=managepage&action=addarttag") ?>', params, function(response) {
    $('#tagwidget'+$id).html(response); // update specific widget area
    });
    }


    This Javascript function is one solution to the problem - you can see how it works here:
    http://www.varnafitness.com/playground.html

    Another, more 'symfonic', solution would be to use the Javascript Ajax helper: form_remote_tag or jq_form_remote_tag (depending on your symfony version):
    <?php echo jq_form_remote_tag(array(
    'update' => 'widget'.$id,
    'url' => 'default?module=managepage&action=addarttag',
    'complete' =>'doSomethingElseFinallySuchAsHighlight()'
    )) ?>

    Wherever possible I prefer using Ajax helpers as it makes code less cluttered.

    If you need further help please let me know.

    Good luck!

  • avatar
    Last edited:
    11/02/11
    1:37pm
    leftrock says:

    Awesome...look forward to hearing from you

  • avatar
    Last edited:
    11/02/11
    1:39pm
    leftrock says:

    You can save ALL of the embedded forms at once with page load..but you cant include a <form> within a <form> technically...so I am handling the adding tags via js + action...added code below

  • avatar
    Last edited:
    11/02/11
    1:52pm
    Luis Cordova says:

    oh wait this is sf1.x, sorry i only do sf2.x

  • avatar
    Last edited:
    11/02/11
    1:54pm
    leftrock says:

    Bummer! Yea...I am moving new projects over to symfony 2 but I need to finish this one off in 1.x

  • avatar
    Last edited:
    11/02/11
    1:55pm
    Luis Cordova says:

    rather if you need me to convert this into sf2, please let me know, it depends on the project. PM me .

  • avatar
    Last edited:
    11/02/11
    6:50pm
    leftrock says:

    Yea this actually makes a lot of sense...seems like I was prob depending too much on the partial helpers :) --- doing it with the "complete" function is a smart solution. Let me play with this for a little but I think your answer looks to be good!

  • avatar
    Last edited:
    11/03/11
    9:52am
    leftrock says:

    I gave your response the full 10 vote...it says "voting in progress" Ill check back later to make sure the prize goes to you...thanks for your help!

This question has expired.



leftrock voted on this question.



Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.