contributte / forms-bootstrap

đź‘ľ Bootstrap 4 + 5 forms for Nette framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Next form duplicates rows

matt-matt1 opened this issue · comments

commented

Hi
Using Contributte Bootstrap forms, I have a form that maybe used multiple times. The first instance looks great, but the subsequent form has the (only) row showing many times.
The form is created in a factory class (in a create() method - code 1) then pulled into my presenter (with creditComponent…Form() method - code 2) then displayed through latte (with render…() method - code 3) using {control …} - code 4.
Inside factory:create(), the form is formed with two fields then a row containing three fields then another separate field. The data is drawn from a database table that may have more than one record. Another issue (.2) is that the first record’s data (values) are displayed in every instance - not just the first. How can I populate each form instance with a database record?
Getting back to the main issue (.1).

code 1

public function create(): BootstrapForm//Form
{
$form = new BootstrapForm;
$form->renderMode = RenderMode::SIDE_BY_SIDE_MODE;
$form->addText('street_address')
->setRequired()
->setPlaceholder()
->setAutocomplete(true);
$form->addText('line2'/)
->setPlaceholder();
$row = $form->addRow();
$row->addCell(4)
->addText('city');
$row->addCell(3)
->addText('province');
$row->addCell(2)
->addText('post_code');
$form->addDate('address_active'))
->setFormat('d M Y');
return $form
}

code 2

protected function createComponentAddressForm(): Form
    {
        $form = $this->addressForm->create();
        return $form;
    }

code 3

$addresses = $this->addressFacade->getAll()
            ->where('business_id', $id)
            ->fetchAll();
        $this->template->addresses = $addresses;
$form = $this->getComponent('addressForm');
        $form->setDefaults(reset($addresses)->toArray());

code 4
{control addressForm}

Am I doing something out of place? If so suggest an improvement with a snippet. Otherwise is there a bug with multiple instances?

commented

Also please explain how to add css classes to the row cell? And I don't mean on the input field. I'd like to add "mx-3" to have the cell spaced away from others.
Another issue: Unless I add css like Bootstrap "row" to the "form-row", each cell in displayed on a separate line. How can I put them inline?
And there's a method "setCurrentGroup()" (on addCell()) How is it used? And "setOption()" on addRow(), same question. Is there docs for these, where?

can U create a minimal project where this is reproduced so I can check more easily?

All existing documentation is here: https://github.com/contributte/forms-bootstrap/tree/master/.docs
Please keep issues simple if U write more issues into one github issue it gets lost. Let's focus on one by one

commented

Here's a screenshot: https://www.imgpaste.net/image/SJQ7W5
I already read that doc - it allowed me to get this far. But it never mentions the method I asked about (eg. setCurrentGroup() & setOption()). Can you provide more detailed docs?
I do not know how to create a minimal project since that data is gathered from MySQL. Unless I can send the entire project and export of the database. Even if I created a zip of all, how can I send it? (This is fairly new project so it is not super large). Now I think about it is deployed to Github - however I think it's private... So do want me to create a public repository and copy over that vital parts? Anyhow can't you make a Nette project and insert the snippets?

Sorry but I do not have time for that. This is opensource project if U find something missing U can allways contributte :-)
I'm willing to help but my time is very limited for opensource projects. You do not need to send database or anything just a simple nette project with contributte-bootstrap installed and mocked up data like you'd get from database, just as a simple array or object and then a latte where this is problem, that way I can play directly on that project and save my time. So minimal code that is runnable and reproduce this problem, without database or any other unnecessary code.

commented

Finally I copied my project to a public repository and made some modifications. The git is at https://github.com/matt-matt1/business-contributte . It has a sqlite database incorporated. You may notice I am also using some other libraries.

The initial screen should present a Datagrid with some dummy data. The CSS is not right, so you'll need to scroll the far right to see the action buttons. When you click 'More' the following page should show the issues I face. The form for the address looks OK for the first but fields are repeated for the subsequent - address 2...

Can you tell me if I am presenting the form wrong? Or provide a work around to make address 2 look like address 1?

Also I am trying to have several fields in a row but they look messy. Why?

Thanks

@matt-matt1 You should probably be using containers here like this: https://doc.nette.org/en/forms/controls#toc-addcontainer ....
YOu're creating here different instances of same form in foreach, without any mark, how will you distuinguish between them? This code won't work... try using addContainer for child items...

@matt-matt1 Closing this, feel free to reopen or open new issue if not resolved