Jump to content

Select Once Per Table: store extra information for selected pages


Robin S
 Share

Recommended Posts

Select Once Per Table

Adds a setting to "Select", "Page (Select)" and "Page (Autocomplete Single)" columns in a ProFields Table field so that each option can only be selected once per table. Requires the ProFields Table module.

There could be a number of situations where this module might be useful, but perhaps the primary situation is when you want to store extra information for pages that are selected in a Page Reference field.

So instead of using a Page Reference field like this...

Without SelectOncePerTable

...you could use a ProFields Table field together with Select Once Per Table to store extra information for each selected page like this...

With SelectOncePerTable

The module ensures that pages/options that are already selected in the Table field are disabled as you add new rows or edit existing rows.

Configuration

To enable the module for any "Select", "Page (Select)" or "Page (Autocomplete Single)" column in your Table field, edit the column settings and add selectOnce=1.

SelectOncePerTable configuration

 

https://github.com/Toutouwai/SelectOncePerTable
https://processwire.com/modules/select-once-per-table/

  • Like 9
  • Thanks 2
Link to comment
Share on other sites

great idea. I could really use it. In my case I have an Autocomplete instead of a Select for the page reference (too many targets) and unfortunately, there double entries are still selectable. But intercepting here, might be another level of complexity. But I might soon find a use case where this fits in well. Thanks for the module!

  • Like 1
Link to comment
Share on other sites

4 hours ago, ceberlin said:

In my case I have an Autocomplete instead of a Select for the page reference (too many targets) and unfortunately, there double entries are still selectable.

I've added support for "Page (Autocomplete Single)" columns in v0.2.0.

  • Like 3
Link to comment
Share on other sites

That's a little bit like Christmas for me. So useful!

An additional reminder under the PW hints for the field might guarantee that this handy option is remembered when the module is active?

• validate: Validates that Pages in value matches your selector on page save.
• selectOnce=1: Each option can only be selected once per table

Link to comment
Share on other sites

  • 1 month later...

There's an issue with autocomplete - until you save you can still enter the same thing in multiple rows. Once saved they are indeed removed from the autocomplete the next time you try to add them but not before saving.

Link to comment
Share on other sites

5 hours ago, Pete said:

There's an issue with autocomplete - until you save you can still enter the same thing in multiple rows.

I can't reproduce that.

The column configuration I used for testing:

2022-01-27_144820.thumb.png.6e1276a1fa1cff4bdd55ee87bc8c3ffa.png

Screencast:

table.gif.8147ea92aee9efd7b692fafa40831717.gif

Is pagination turned on for your Table field by any chance? Can you provide steps for a basic test case where the problem occurs?

  • Like 1
Link to comment
Share on other sites

You're right, it is working. I think I fell foul of having changed the table schema and sometimes it can get itself a bit mixed up. When I stripped out some extra settings from when my first column was a different fieldtype and re-saved it started behaving itself just fine.

Thanks for checking!

Link to comment
Share on other sites

Aha, I managed to get this to happen again.

Step 1: delete two PageAutoComplete entries and save the page - the empty rows remain (I really wish empty rows wouldn't get saved but that's another story):

image.png

Step 2: Typing into the fields in the two existing empty rows you can enter the same value twice (so below I just entered the Parkland Resort extra into the first of the two empty rows, and am able to add it again in the second of the empty rows)

image.png

It respects the once-per-table setting when you add a new row, but not for empty existing rows. I do wonder if another belt-and-braces solution here is to simply check for and delete duplicate rows on save too?

  • Like 1
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

×
×
  • Create New...