Jump to content

ProFields Table: Edit/Delete Specific Item


Carl Booth
 Share

Recommended Posts

Hi

I can anyone help me with manipulating ProFields Table rows?

It works ok using first() and last() as per the README, however I can't seem to manipulate specific items, given a selector. I presume I'm doing something wrong when selecting the row(s).

    $tt = $pages->findOne("template=repeater_basetimetables,title=Silver")    

    // Works - from README
    $page->of(false);
    $opday = $page->operatingcalendar_days->last();
    $opday->timetable = $tt;
    $page->save('operatingcalendar_days'); 

    // Doesn't work - set to TableRows is not an allowed type
    $page->of(false);
    $opday = $page->operatingcalendar_days("ttdate=2022-08-11");
    $opday->timetable = $tt;
    $page->save('operatingcalendar_days'); 

    // Doesn't work - no error
    $page->of(false);
    $opday = $page->operatingcalendar_days("ttdate=2022-08-11")->first();
    $opday->timetable = $tt;
    $page->save('operatingcalendar_days'); 

Or, do I have to remove and re-create rows I want to modify?

Cheers

Edited by Carl Booth
changed code listing
Link to comment
Share on other sites

Hi Carl, welcome to the PW forums!

Sorry, it’s not clear to me what $award and $tt are in your code? Also, it looks like you’re getting a table row into $opday and then never do anything with it? But yeah, modifying a specific item is described in the module’s readme:

$page->of(false); // turn off output formatting, if necessary
$award = $page->awards->first();
$award->title = "Most Sustainable Building";
$award->date = "2014-05-01";
$page->save('awards');

(I only have an exceedingly old version, your readme may differ.)

Btw, there is a dedicated support board for ProFields, if you have access (I don’t).

  • Thanks 1
Link to comment
Share on other sites

Hi Jan

Thanks for the welcome.

$award->timetable is an artefact of me copy and pasting wrong, it should be $opday->timetable, which is a Page reference field in the table. $tt is a Page, the comment at the end that explains how I've assigned it ($pages->findOne). However I'm having the same problem if the field is a plain text.

Your example (from the README) works correctly for me (it's essentially the first block in my code) however that's only the first() or last()) item - I'm needing to edit a specific filtered row (or set of rows) - those with a specific field value. I think this is what I'm struggling with - capturing those rows and editing them in a way the module will write back to the database table.

Cheers

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...