buttflattery / yii2-formwizard

A Yii2 plugin used for creating stepped form or form wizard using yii\widgets\ActiveForm and \yii\db\ActiveRecord
https://yii2plugins.omaraslam.com/formwizard
Other
96 stars 13 forks source link

Preview step: multiple files count instead of field-value list #61

Closed mondomeme closed 4 years ago

mondomeme commented 4 years ago

I'm to use kartik file input widget for uploading multiple files. I successfully load and save the the files, but in the preview step I would like to see a the number of files loaded instead of upload model fields. Thank you.

buttflattery commented 4 years ago

Well every widget uses its own HTML and can include different implementations of the HTML structure which isnt covered in it , you might have to add your own implementation for the $.formwizard.preview.getLabel() which should work with the widget to display label, otherwise it will show undefined as it expects by default that the label will be the sibling of the input, the file count is added via abad988

mondomeme commented 4 years ago

@buttflattery I'm sorry if I respond only now, but I tried to override the function in the view in which I render the form wizard, adding this code : $this->registerJs(<<<JS $.formwizard.preview.getLabel = function(fieldName){ let text = $('#' + fieldName).siblings('label').text(); console.log(text); //only for test purpose if (text !== '') { return text; } return $('#' + fieldName).attr("placeholder"); } JS ); . When I load the page I have the following error: $.formwizard.preview is undefined

buttflattery commented 4 years ago

@mondomeme you should try loading the scrip on the DOM READY using the \yii\web\View::POS_READY as the second parameter of the $this->registerScript()

mondomeme commented 4 years ago

@buttflattery I tried to use the POS_READYas second parameter of $this->registerJs(), but I have the error TypeError $.formwizard.preview is undefined

buttflattery commented 4 years ago

Well what you are doing wrong is may be my mistake too somehow as i linked the code with the title $formwizard.preview.getLabel whereas it is actually $.formwizard.previewStep.getLabel :/ sorry for that i just realized that after doing some audit @mondomeme

mondomeme commented 4 years ago

@buttflattery ok, now it works perfectly. Thank you

buttflattery commented 4 years ago

your are welcome @mondomeme