This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

billyZduke
billyZduke

I've extended the User model and I'm trying to add a jsonable field for notes that a backend admin can add to each user. I figure since this is JSON data, I should be able to add multiple fields for each note, but not sure if I should be using a separate Note model to define these fields, as I'm finding conflicting information from various other people's posts on the subject of the repeater field. Plus I also want the backend admin to be able to see the full text of notes, edit or delete existing notes, and add new notes while still on the page for the User record.

So, I have already included 'notes' in the jsonable property of my extended User object. Then I use a yaml config file and the addTabFields() function to include the notes field in its own tab in the backend display of any given user record. And here's where things go awry: no matter what I do with this yaml file, by clicking on the "Add New Item" in the repeater when looking at the User in the backend, ALL the user fields get included in the new subform created by the repeater. My field yaml follows. Any ideas?

notes:
    label: Notes
    tab: Notes
    type: repeater
    prompt: Add New Note
    form:
        include: false // Saw someone else using this for what seemed like a related issue, but it has no effect either way.
        fields:
            notes[created_at]: // I've tried using just created_at here... Ideally I'd like to automatically save the note creation timestamp along with the note data itself, without the backend admin user having to select a datetime.
                label: Created
                type: datepicker
                default: now
                hidden: true
            notes[note]:
                label: Note
                type: richeditor
billyZduke
billyZduke

For the sake of expediency, I gave up on the repeater for the moment, instead I just used a single textarea/richeditor to create one big notes field... But I would like to know how I could have made the above work, and where the middle ground is between using a relation widget and a jsonable field... I've gotten the jsonable field stuff working with a repeater in the past, but that was with a hasMany relationship to a mediafinder object... A solution I found elsewhere in this forum. In this case there are no other tables/models or relations involved... but should there be?

billyZduke
billyZduke

So, I took another crack at this today, from a different angle: I created a UserNote model in my plugin and set up a hasMany relationship (this was also the point where it finally dawned upon me that hasMany() & attachMany() are not the same thing, not at all) with the extended User model. So, one User hasMany Notes, made a database table with migration, all well and good to start.

I was trying to get a nice modal pop-up form to create and edit the notes, like in Renatio's Form Builder plugin. In his version, one Form hasMany Fields, and when you are looking at the Edit Form page, you see a list of fields, clicking on any one of them brings up the modal form so you can edit the field data without leaving the Edit Form page. This was an ideal behavior to emulate.

And I got pretty far with it... I can see the list of Notes in a tab on my Edit User page, and I do get a popup when I go to Create a new note... But here's where I get approximately the same error that occurred during the JSON attempt: all the fields from User are being duplicated and added to my form for Note. I'm still trying to figure out how Renatio keeps this from happening with his Forms & Fields, and if this bug is specific to the User plugin or in my extension of it (most likely the latter, obviously).

So what's really going on here, and how can I stop it from happening? Please help... I know my posts are long but that's cause most of the requests for help I read are far too short and don't contain enough relevant info. Just trying to relate the specifics of my whole story...

LilEssam
LilEssam

Well, I don't even understand your problem without seeing all your code.

But I think you can solve this problem by creating a plugin with a similar idea with Builder and you can see the final code in the YAML files so you can understand.

billyZduke
billyZduke

Remade a demo plugin in the builder with simple User and UserNote models/tables, and in there the modal form functionality I wanted worked immediately/automatically... (Though the Builder itself does not provide for modal form based on model relation, hand editing of Yaml and creation of _notes_fields.htm required.)

<?php echo $this->relationRender('notes') ?>

I've got a lot of other things going on in my custom User extension plugin, so I realized something must be conflicting... After adding and deleting different controller & yaml files for awhile, I noticed that the unwanted extra fields being added to the Notes form were only the ones from the Profile tab, in other words, only the ones added by the UserPlus plugin.

So, then I took what I needed from UserPlus into my own custom plugin and disabled UserPlus, and suddenly all works as expected. I guess that "experimental" tag on UserPlus wasn't kidding.

Last updated

1-5 of 5

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.