Metamagik hide field in create task

I am using Metamagik plugin to add more fields in the task. One of them, I don’t want it to appear when the task is created or modified, because I want a dynamic field that is automatically filled and cannot be modified, how can I do it?

Well, it would definately require some coding. Is that what you are asking, how to code it?

Yes, i don’t know where start.

I see that the extra field are filled in task_creation template in this line:

            <?= $this->hook->render('template:task:form:first-column', array('values' => $values, 'errors' => $errors)) ?>

but then i don’t no how to do it

well, you are going to need to do a few things.

1st - you need a way to determine if a field is visible or not, which will require adding information to the MetadataType, similiar to “Include Footer”

2nd - You need to add to the template a way to input the above information to save into the MetadataTypeModel, again, similar to “Include footer”

3rd - you then need to check for that information upon displaying fields, and determine if it will be displayed or not, which will require adding a method in the model to supply such information and a way to check for such information within the templates responsable for displaying such information. Again, look for “Inlcude Footer” examples on how that works, because it is essentially doing exactly what you are asking for, just in a different location.

Also, ignore the hook, thats not where you are going to do anything, it’s the template that is “hooked” to the hook where you will be doing it, among everything else i listed. But basically, everything you need to do to hide the input of a custom field, is already being done for “Include Footer”, so you have all the examples to do what you need to do. Don’t forget though, “Task Creation” and “Task Modification” are different things, so you need to do it both places, not to mention “Task Duplication”, which won’t need anything hidden, but if your looking for a uniquely filled number, this would result in a duplicate number.

Then there is the question of automatically filling the data, thats going to require even more.

There is also the question of “That cannot be modified” and that becomes even more, as even if you hide it, it can definately be modified.

1 Like

For fill the data what do you think is better, shown the field in the form but make it disabled with the data filled or do the things that you comment above and then fill the data of this field?

Thats really a preference only you can determine. I dont think it would affect how it would be filling the data either way. Its hard too answer any more without knowing “what” you want to fill it with.

Finally, i have chosen by shown the field and make it enabled but filling the data automaticly, I think is the better option for the future.

I have a meta field with name idNk, when a new task is added the field idNk i’m triying fill with this information:

    public function getLastIdentifyer()
    {
        $lastID = $this->db
        ->execute('SELECT max(value) FROM kanboard.task_has_metadata where name="idNk" and value!="PXXXX" and value LIKE "P%"')
        ->fetchAll(PDO::FETCH_ASSOC);
        
        $lastID = implode($lastID[0]);
        return $lastID;
        
    }

Then i tried to include the follow sentence in function show in taskcreationcontroller:

$lastID = substr($this->taskMetadataModel->getLastIdentifyer(), 2);

But when i put the lastid in the array in the render doesn’t work. I tried diferents things but i don’t obtain the result that i want

Nope and nope.

I don’t know what you are doing here, it look like you are trying to get information, not fill information, but this is not how you GET information from the task_metadata table:

public function getLastIdentifyer()
    {
        $lastID = $this->db
        ->execute('SELECT max(value) FROM kanboard.task_has_metadata where name="idNk" and value!="PXXXX" and value LIKE "P%"')
        ->fetchAll(PDO::FETCH_ASSOC);
        
        $lastID = implode($lastID[0]);
        return $lastID;
        
    }

And then same here:

$this->taskMetadataModel->getLastIdentifyer()

You are attempting to call a function that doesn’t exist, unless you have added that function in the taskmetadata model, but again, why would you do that? Leave that model alone! It didn’t do anything to you!

If you want to get information from the taskmetadata model use:
$this->taskMetadataModel->get($task['id'], 'idNk', '')
unless you are trying to do it within a template, then use:
$this->task->taskMetadataModel->get($task['id'], 'idNk', '')

if you want to save information to the taskmetadata model use:
$this->taskMetadataModel->save($task_id, ['idNk' => $value])
and again, add ->task if you are in a template

all the code that determines WHAT that value should be, should be somewhere else. i.e.

public function create_identifier()
{
   do some stuff;

   return $value;
}

and then in the helper, you add a render for said field:

public function renderMeta_idNk($key, $value, array $errors = array(), array $attributes = array())
    {
        $html = "";
        $html .= $this->helper->form->label($this->beautyName($key), 'metamagikkey_' . $key);
        $html .= $this->helper->form->text('metamagikkey_' . $key, ['metamagikkey_' . $key => $value], $errors, $attributes, 'form-input-small');
        return $html;
    }

You can use the “attributes” to define disabled if need be, I would suggest looking at the “FormHelper” in kanboard.

1 Like

Oh and if this is a whole new type…you need to also account for it here:

i’m not gonna lie, this is one confusing plugin, code wise :slight_smile:

1 Like

Is a field added in Custom Fields, so when I add the render appears two times, one by render and other by hook render first column.

I need that my variable lastID is filled in the input Identifyer(green line).

I see in the repositorie that the form is doing that I need, in this picture:

Is done like you tell me?

finally got it! I have included the value within the preparevalues ​​function, with the name assigned to the input

1 Like