Dynamically adding fields to record

Hi, I’ve been trying to look for dynamically added field examples online but didn’t have much luck except for paid solutions on the store. What I’m trying to achieve simply is a textbox, that can be added and removed as this isn’t always a fixed amount. Is there anywhere in the documentation that would help me achieve this?

Not directly answering your question, but wouldn’t it be more in line with the architecture to simply use a related module, and a subpanel for that?

You want a variable number of items in a record - that’s a one-to-many relationship, and in SuiteCRM that is handled with related modules and subpanels.

Even if you really need to do something different, something extra, I would still recommend starting from that base and elaborating from there.

Hey pgr,

That’s a pretty good idea, hadn’t thought of that - I’ll test it out and see how it looks. The reason that I would like to do it the other way is mostly because it would look better, and because there is more than likely fields that will be in different places on my module’s edit view. I usually haven’t been messing much with UI other than studio and css, most everything I do is in APIs so front end is usually a mystery to me with template engines and such

Try it, I’m almost sure it will work out for you. Working with the architecture, instead of against it, saves you a ton of problems.

You might have a few details to iron out, which you can probably do with customizations, but I’m confident you’ll discover that the advantages and simplicity of using a standard solution will outweigh them.

1 Like

Doing this has the desired functionality I wanted, but I was wondering if there was any way I can get a subpanel onto the edit view? It can be tedious having to go to detail view to finish the rest of your data entry. I saw you had replied to someone about this topic a couple of years ago in a post saying how this wouldn’t allowing saving of the record properly - is this still the case?

I read about it on this blog: subpanel in edit view

Nothing has changed in SuiteCRM since that time, in this regard.

That blog post seems to provide a solution. Also make sure your users know how to use inline edit (double-clicking field to edit them directly in detail or list views).

That was a lot simpler than I thought it was going to be :sweat_smile: thanks for the subpanel idea. This is what I changed in case anyone needs to do this:

I created a new ‘view.edit.php’ in /custom/modules/{moduleName}/views/ (I had to create the views folder)

if (!defined('sugarEntry') || !sugarEntry)
{
    die ('Not A Valid Entry Point');
}

class {moduleName}ViewEdit extends ViewEdit
{
    public function __construct(){
         parent::__construct();
         $this->options['show_subpanels'] = true;     
}
}
1 Like