Lenz

Frontend Editing: Managing data rows (e.g. Fieldtype table)

Recommended Posts

Hello all,

i have a question regarding the following scenario:

My customer wants to edit a menu card of a restaurant website directly in the frontend.

Each dish / menu is displayed in a row with 4 simple textfields (position nmbr, name, quantity (optional, for drinks) , price).

My customer preferably not only wishes to edit/update existing fields/rows, but also add a new one, delete one, or move an existing one up or down to a new position in the card.

Would these actions be possible per default in the frontend edit mode, if i'd have e.g. a table profield storing the 4 textfields per dish? Or is this only functional in the backend?

In a demo video of a Profield (-> fieldtype table) i saw the requested edit functionality (edit or add a row of fields, drag a row up/down, delete a row, safe) in the backend...

Btw., regarding this concrete use case of a menu card: Would i have to use at all a Profield like table or could i accomplish the task also with a Repeater Field or a Pagetable fieldtype?

In any case at least i don't want to let my customer mess around with a richtext field / inserting a table within CKEditor in the backend...

Maybe there are better approaches than the above mentioned.

 

Edit: I should add, that the site is a static one, equipped with an meanwhile dysfunctional inline frontend editor (that had the capabilitiy of editing, moving, deleting such rows directly inline in the frontend).  Now i want to replace this editor with processwire.


Thanks in advance

Share this post


Link to post
Share on other sites

Here is what I've made similar to this, using Table and Matrix modules, but the same could be achieved with the built-in Repeater too.

 

  • Like 1

Share this post


Link to post
Share on other sites

Thanks @tpr for your answer. Good job!

As i can see in your example: The frontend editing is only possible with a modal layer here? Or precisely could the modal layer display the edited page wysiwyg instead of their backend view?

I mean with the build in frontend editor: Is it possible to edit repeaters or table fields directly inline without a modal layer or with a modal layer displaying the page wysiwyg? If so, would i also have CRUD functionality and drag&drop available?

 

Share this post


Link to post
Share on other sites
5 hours ago, Lenz said:

Is it possible to edit repeaters or table fields directly inline without a modal layer or with a modal layer displaying the page wysiwyg?

Superusers may edit individual repeater items inline (not in a modal) but non-superusers may not. There's an open issue regarding it (with a possible workaround you can use at your own risk) but based on Ryan's comment here I think he is not inclined to view this as a bug to be fixed.

  • Like 2

Share this post


Link to post
Share on other sites

As I remember I had issues with the inline editing (even if SuperUser) because the site was multilanguage and I had to switch languages in each line. But normally this shouldn't be an issue as this was a special case.

Share this post


Link to post
Share on other sites

@Lenz what is so bad about the admin UI? see this post for example using the adminbar module

there is also FREDI and FEEL. not as good as real frontend-editing, i admit, but close :)

  • Like 1

Share this post


Link to post
Share on other sites

Thanks a lot @Robin S @tpr @bernhard for your valuable input. I have a few remaining questions

 

6 hours ago, Robin S said:

Superusers may edit individual repeater items inline (not in a modal) but non-superusers may not. There's an open issue regarding it (with a possible workaround you can use at your own risk) but based on Ryan's comment here I think he is not inclined to view this as a bug to be fixed.

 

Does this mean, that i can only edit Repeater items in inline mode and that i haven't CRUD functionality available in inline edit mode? Meaning, i can't add a new repeater, delete a repeater or drag a repeater to a new position? (see my example with the menu card, where every line/dish would be represented with a repeater )

 

1 hour ago, bernhard said:

@Lenz what is so bad about the admin UI? see this post for example using the adminbar module

there is also FREDI and FEEL. not as good as real frontend-editing, i admit, but close :)

@bernhard Actually nothing is bad about the Admin UI, if you ask me. It looks even good. But unfortunately my clients are accustomed to edit directly inline wysiwyg and don't want to give up this experience...

@all: Let's say if i could convince my customers so they accept FE within Processwire as it is: Do you think that regarding my use case (see my first post) a repeater would do the job perfectly fine or has a Profield like "table" maybe advantages over a Repeater?

Meaning, if i have 4 simple textfield wrapped in a Repeater vs wrapped in a Profield table field: Are these 2 scenarios essentially behave the same or are there differences?

There are round about 100 - 150 entries in the menu card (inclusive beverage)

Share this post


Link to post
Share on other sites

you could use the core pagetable field, then you would also have frontend editing. adding and removing items would need some manual work but would not be very hard (send an ajax request, create a page with dummy-data, reload the frontend, double click to edit text)

  • Like 1

Share this post


Link to post
Share on other sites

hi @bernhard, as for implementing an ajax request: Don't know how to accomplish that, never did this before...wait, no, recalling one incident implementing a registration form with ajax, it was a terrible experience... never got it really working, XAJAX comes to my rescue at that time ... :-)

Regarding the pagetable field for FE: But wouldn't a Repeater work for FE too, if i understand the posts above correctly? Or do you think a pagetable field is a better fit for a special reason?

Share this post


Link to post
Share on other sites
7 hours ago, Robin S said:

Superusers may edit individual repeater items inline (not in a modal) but non-superusers may not. There's an open issue regarding it (with a possible workaround you can use at your own risk) but based on Ryan's comment here I think he is not inclined to view this as a bug to be fixed.

as far as i understood this would only be possible for superusers and i would definitely not give your client superuser access...

i think you have those options:

  1. profield table
    backend gui, but very clean and easy to manage, 150 items is a lot though
  2. repeater
    backend gui, little more "bloated", not sure how this would work for 150 items...
  3. pagetable
    you could use FE, but you need to implement add/delete/move functionality on your own. add/delete would be very simple, move would be a little more complicated.
    you could also do the sorting based on the position number (item number, seems to be your first field). that would maybe be not so user friendly.

how do you plan to do the item numbering? automatically? why do you plan to have a field for that?

  • Like 1

Share this post


Link to post
Share on other sites

the item numbering is actually the dish position number: like Nr 71 | fried chicken | 7,90  like in these chinese cards :-)

edit: Maybe it's indeed better to do the numbering automatically, i agree. The customer said, that he wants to edit the number, but i don't remember at the moment, why...- i defiinitely will clarify this.

It really seems to me, that pagetable is the option to go for me. Thanks for clarification.

Regarding implementing at least add / delete items in inline editing: @bernhard could you point me to some good resources, where i could learn how to accomplish this? - Really thanks for your engagement !

 

 

Share this post


Link to post
Share on other sites

the button somethink like this

<a href="./?add=1">add item</a>

the code something like this (in your template)

<?php
if($input->get->add) {
  $parent = $pages->get( your parent page );
  if($parent->addable()) {
    // create a new page and save it
  }
}

// continue with your regular template code
foreach($pages->find('yourselector') as $p) {
  // list your products
  // will already contain your new item
}

you could also make different add-buttons that hold some variables (like category or the like)

---

delete:

<a href="./?delete=123">delete item</a>

and the code:

<?php
if($input->get->delete) {
  // find page that should be deleted
  $p = $pages->get($input->get->delete);
  if($p->id AND $p->trashable()) $pages->trash($p);
}

this would always need a page reload. with ajax the user experience would be much nicer (page not jumping around)

 

hope that helps - but maybe someone has better suggestions ;)

  • Like 2

Share this post


Link to post
Share on other sites

wow @bernhard. Thanks. Thats a good start.

As for Ajax. Yes, of course i'd like to do the actions without page reloading. Hm, could you point me to a good tut or resource? I haven't enough knowledge how to interact with PW if i want to implement actions the AJAX way...

Share this post


Link to post
Share on other sites

ah by the way: you don't need a pagetable if you stay with this solution. you can just store all items under one parent. that makes things a little easier usually

Share this post


Link to post
Share on other sites
9 hours ago, Lenz said:

Does this mean, that i can only edit Repeater items in inline mode and that i haven't CRUD functionality available in inline edit mode? Meaning, i can't add a new repeater, delete a repeater or drag a repeater to a new position? (see my example with the menu card, where every line/dish would be represented with a repeater )

I'm a bit confused about exactly what you want to do, but it sounds like the default frontend edit behaviour (where non-superusers edit a repeater field via a modal) is exactly what you need. When your editor goes to edit anything in the repeater on the frontend they get a modal where they can edit any of the fields within a repeater item, add new repeater items, delete them, drag them, etc.

In your template file you surround the entire repeater foreach() with edit tags (editing method C or D) - have you tried this yet?

Share this post


Link to post
Share on other sites

@Robin S  haven't try this yet. But you're right, many requirements would be met with your suggestion.

Obviously i'm a bit unclear, indeed: So my wish is to edit directly inline wysiwyg without a modal layer, like you do e.g. with textareas. But meanwhile i learned, that's - at least per default - only possible with textfields or textarea fields, but not with repeaters, table, pagetable, image, file field types. For "complex" field types you have always a modal layer for frontend editing. And the modal layer displays the backend/admin ui edit-view of the field, not wysiwyg / not the page layout.

So to achieve INLINE WYSIWYG frontend editing with CRUD + DRAG functionality, i have to invest quite a bit of hacking - without much knowledge of AJAX, which in turn would almost be necessary to not have page reloads all the time and to resemble the old edit experience...

My customers are accustomed to edit / add / delete and drag data rows/ table rows directly inline wysiwyg and want to retain their edit-experience. But meanwhile, if i see e.g. the demo video of the Profield table field, the backend edit view is really very clear and unbloated. Repeaters are a bit more bloated and scale perhaps not so good as table fields. Perhaps i can convince my customers to go this route.

And the table field should be accessible to frontend editing the same way as repeaters or pagetable fields do, i assume?

Share this post


Link to post
Share on other sites
14 minutes ago, Lenz said:

For "complex" field types you have always a modal layer for frontend editing.

Yes, that's what it boils down to basically. There are several reasons for this depending on the fieldtype to be edited, but in the case of a repeater PW has no idea what you are doing in terms of displaying your repeater output on the frontend - it gives you total flexibility there. So PW cannot really provide an inline frontend interface for drag-sorting repeater items for instance, because there is no guarantee you are even presenting all of your repeater subfields contiguously inside a single containing div.

So I think you'll need to resign yourself to modal editing unless you are up for some serious custom frontend interface work.

I'm curious to see the existing interface your client is using - it sounds quite fancy. Maybe you could post a video? (LICEcap is useful)

 

14 minutes ago, Lenz said:

Repeaters are a bit more bloated and scale perhaps not so good as table fields. Perhaps i can convince my customers to go this route.

And the table field should be accessible to frontend editing the same way as repeaters or pagetable fields do, i assume?

Repeaters scale to a medium level fine so long as you use the AJAX-loading setting.

I haven't tried Table with frontend editing but I think any fieldtype becomes editable via a modal.

  • Like 2

Share this post


Link to post
Share on other sites

Thanks for your explanation, @Robin S makes sense.

Ok, one question: If i have 150 items, should i better go with the Profield table or is a Repeater enough? I really like the nice unbloated editing view of the table field. Does it scale better? Is it also like a Repeater accessible for frontend editing (via modal)?

Video of current fancy editor: Problem is, the editor is not working anymore, so unfortunately i could not show you a video. The editor called unify, but it's not developed anymore and the business around it is gone. It was essentially a ajax frontend without a database for managing content for static sites (directly write into the files). At this point i fear i made a mistake in describing the editing experience: If i remember correctly you actually also have a modal layer, as soon as you edit content - but it loads the page layout - so you edit wysiwyg. Dragging / sorting rows was indeed possible directly inline without a modal though.

Similar editors are https://sitecake.com/  and http://www.coast-cms.de/

but i'd like to use Processwire

edit: Thanks @Robin S for refering to my question regarding table field and frontend editing.

Could perhpaps someone confirm that also the table field is frontend editable?

Share this post


Link to post
Share on other sites
1 hour ago, Lenz said:

Ok, one question: If i have 150 items, should i better go with the Profield table or is a Repeater enough? I really like the nice unbloated editing view of the table field. Does it scale better?

The thing that can potentially allow Table to scale up to a very large number of rows is the ability to paginate the rows, both in output and in the admin interface. Pagination is not enabled by default but is an option.

You could probably have 150 rows in an AJAX-loading repeater without a technical issue, but for both Table and Repeater you could have a bit of a usability issue with that number of rows. Imagine dragging a row from bottom to top for instance. And I don't know if that's even possible with a paginated Table interface (how do you drag from the last page to the first?). But these problems seem like they just go with the territory of what you are needing to do and the number of items you need to support.

If you think you will work on more PW projects I'd say it's definitely worth purchasing ProFields. It's fantastic value for money, just for Table and Repeater Matrix alone.

  • Like 4

Share this post


Link to post
Share on other sites

Thanks again @Robin S. I think i'll go with the Profield. As i understand, it should also be frontend editable via a modal. This way i have the best editing experience and at the same time i support the Development of Processwire.

Thanks @all for your help.

  • Like 3

Share this post


Link to post
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


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By nico65
      Hello,
      the frontend edit mode in pw3 is allready great. But I'n looking for a solution where I can have the create/update form on a edite page. (url/urlsegmaent=edit).
      With all the released code here I was able to put together some code that does that.
      So far it works to fill the page for the first time, but unfortunaly it dosen't work so great on updating the page.
      When I try to update, the page disappears from the frontend. Its still visible in the backend but seems to be corrupt.
      Here is the code I used:
       
      <?php namespace ProcessWire; ?> <?php $content =''; ?> <?php $content = ''; $out = ''; if ($input->urlSegment(1 ) =='edit'): if(!isPageOwner()) throw new Wire404Exception(); // Edit Form // get a page $editpage = $page->setOutputFormatting(false); $ignorefields = array("isOld","user_activation","language_published","roles","admin_theme"); $form = $modules->get("InputfieldForm"); $form->method = 'post'; $form->action = './'; // get the collection of inputs that can populate this page's fields $inputfields = $editpage->getInputfields(); // make all the fields required and add them to the form foreach($inputfields as $inputfield) { if(in_array($inputfield->name, $ignorefields)) continue; $form->add($inputfield); } // the inputfields don't already have a submit button, so we'll add one. $submit = $modules->get("InputfieldSubmit"); $submit->name = "submit"; $submit->value = 'Submit'; // add the submit button the the form $form->add($submit); // process the form var_dump($editpage->snippet_repeaterblock->first()); echo '<hr>'; var_dump($editpage->snippet_repeaterblock); echo '<hr>'; $rpf_count = $editpage->snippet_repeaterblock->count(); echo $rpf_count; if($this->input->post->submit) { echo $firstRepeaterId; $n = 1; $codesnippet = "snippet_code_repeater$n"; $codelanguage = "snippet_select_codelanguage_repeater$n"; $snippet_repeaterblocks = $editpage->snippet_repeaterblock; // the repeaters foreach ($snippet_repeaterblocks as $item){ # $item = $pages->get("id=$snippet_repeaterblock->id"); // the repeater page we want to update $item->of(false); // update repeater fields $item->snippet_code_repeater = $input->post->$codesnippet; $item->snippet_select_codelanguage_repeater = $input->post->$codelanguage; // save the repeater page $item->save(); // update counter etc $n++; $codesnippet = "snippet_code_repeater$n"; $codelanguage = "snippet_select_codelanguage_repeater$n"; } # New Code End // now we assume the form has been submitted. // tell the form to process input from the post vars. $form->processInput($this->input->post); // see if any errors occurred if( count( $form->getErrors() )) { // re-render the form, it will include the error messages $out .= $form->render(); } else { // successful form submission, so populate the page with the new values. foreach($form as $field) { $donotpopulate = array("snippet_repeaterblock"); if(in_array($field->name, $donotpopulate)) continue; $editpage->set($field->name, $field->value); echo $field->name; echo ':'; echo $field->value; echo '<hr />'; } // save it $editpage->of(false); $editpage->save(); $out .= "Page saved."; $out .= $form->render(); $content .= $out; } } else { $out .= $form->render(); $content .= $out; } else: ?> <?php /* -------------------- UserProfile */ ?> <?php $cuser = $page->createdUser->id; ?> <?php $cusername = $users->get($cuser)->name; ?> <?php $cusermail = $users->get($cuser)->email; ?> <?php # print_r($page->createdUser); ?> <?php /* -------------------- TAGS*/ ?> <?php $snippet_tag_count = count($page->get("snippet_tag")); $allsnippettags = $page->get("snippet_tag"); if ($snippet_tag_count > 0 ): $tagcontent ='<ul class="snippet_tags">'; $tagcontent =''; $tagcontent .='<ul class="all-tags">'; foreach ($allsnippettags as $allsnippettag) : $alltagtitle = $allsnippettag['title']; $alltagid = $allsnippettag['id']; $alltagpath = $allsnippettag['path']; $alltagurl = $baseurl.$alltagpath; $tagcontent .='<li class="all-snippet_tag">Tag: <a href="'.$alltagurl.'">'.$alltagtitle.'</a>'; # print_r($allsnippettag); ?> <?php $tag = $allsnippettag['name']; $matches = $pages->find("snippet_tag=$tag"); $matchescount = count($matches); $tagcontent .='<ul class="tags">'; foreach ($matches as $match) : $tagtitle = $match['title']; $tagid = $match['id']; $tagpath = $match['path']; $tagurl = $baseurl.$tagpath; $tagcontent .='<li class="snippet_tag "><a href="'.$tagurl.'">'.$tagtitle.'</a></li>'; endforeach; $tagcontent .='</ul>'; $tagcontent .='</li>'; endforeach; $tagcontent .='</ul>'; endif; ?> <?php $content .= "<div id='snippet' edit='snippet_repeaterblock,snippet_tag'>"; $content .= "<p>Create Snippet</p>"; foreach ($page->snippet_repeaterblock as $repeater_item) { if ($repeater_item->get("cb_desc_code")): $content .= "<div class='snippet_description'>" . $repeater_item->get("snippet_description") . "</div>"; else : $content .= "<pre><code>" . $repeater_item->get("snippet_code") . "</code></pre>"; endif; } $content .= '</div>'; $content .= $tagcontent; $content .= '<div class="CreatedUser"><a href="'.$baseurl.'snippets/'.$page->createdUser.'" >'.$cusername.'</a></div>'; If someone has some ideas that would be great.

      Best
      Nico