wbraganca / yii2-dynamicform

It is widget to yii2 framework to clone form elements in a nested manner, maintaining accessibility.
Other
436 stars 438 forks source link

BC BREAK: Regexp change breaks nested dynamicforms #263

Closed tafid closed 6 years ago

tafid commented 6 years ago

The recent Pull Request https://github.com/wbraganca/yii2-dynamicform/pull/256 contains a regression. When dynamic forms are nested (as shown in the Demo 3, the updated regular expression leads to wrong parsing of inner dynamicform instance that leads to break of sequence enumeration and, as a result, break of custom scripts that rely on the sequential input ID's.

From my point of view, that commit should be reverted and the problem with UUID should be re-evaluated with a proper testing.

tafid commented 6 years ago

New regex vs old one

SilverFire commented 6 years ago

Confirmed

wbraganca commented 6 years ago

Done! Thanks.

SilverFire commented 6 years ago

Thank you for a prompt reaction

tafid commented 6 years ago

Thanks!

maranqz commented 6 years ago

265

Many be it is good regex for solving? ^(.+?)((?:-[\d]{1,})+)(.+)$ https://regex101.com/r/F93CGX/1

Legion112 commented 6 years ago

In my opinion, this regex must be configurable like this.

DynamicFormWidget::begin([
                    'widgetContainer' => "dynamicform_wrapper"
                    'widgetBody' => ".container-items"
                    'widgetItem' => ".item"
                    'min' => 1, // 0 or 1 (default 1)
                    'insertButton' => ".add-item"
                    'deleteButton' => ".remove"
                    'model' => $personalData[0],
                    'formId' => 'common-form',
                    *'regexID' => "^(.+?-$model->tour_id-.+?)(-\d{1,}-)(.+?)$",*
                    *'regexName' => "(^.+?\[$model->tour_id\]+.+?)(\[\d{1,}\]{1,})(\[.+\]$)",*
                    'formFields' => [
                        'first_name',
                        'last_name',
                        'birth_date',
                        'gender',
                        'citizenship',
                        'passport_number',
                        'passport_expire_date',
                        'file'
                    ],
                ]); ?>
Legion112 commented 6 years ago

@wbraganca

I have several projects where I have extract this widget and make this regexID, regexName configurable.

If you'd like I could make a merge request with this future. )