Use a file input widget instead of the built in input field.
Related to #8779
The widget should (be able to) set the enctype for the form.
The InputWidget doesn't get a reference to the form it is used in, so it cannot change the forms enc type.
$config['form'] to yii\widget\ActiveField::widget(). $form property to yii\widgets\InputWidget.hasForm() method to yii\widgets\InputWidget, analogous to hasModel().This will allow input widgets to alter the form in which they are embedded; it will add virtually no overhead for people not using it. It will not break BC.
its a bit of a pain to pass "form" to all the widgets..
i overwrited the controller widget stack to allow me to find the first form so i could access its from out there.
$widget->owner->geWidgetFromStack(Form::class)
I considered that as well. I'd prefer to have it standardized inside the framework though.
I agree it to be logical to have a mutual connection between related objects like a Form and Fields. Enough usecases can be imagined. It seems to be a BC break though for those not using InputWidget as a widget tied to ActiveField.
@dynasource It doesn't break BC, the form parameter is optional, this is basically the same approach as used by the various parts of Yii that work both with and without a model. --> See my original post.
whats the usecase to use it without the inputfield?
@TerraSkye I don't understand what you mean.
In what usecase can u not use form->textfield->widger
InputWidget should be tied to ActiveField instead of ActiveForm as ActiveField::$form already allows getting form from field.
class MyInputWidget extends InputWidget
{
public function run()
{
$form = $this->field->form;
}
}
That's fine with me as well, @klimov-paul how do you propose to implement that?
Same as my proposal for form but then replaced with field?
hasFieldpublic $fieldclass InputWidget extends Widget
{
// ...
public $field;
// ...
}
class ActiveField extends Component
{
// ...
public function widget($class, $config = [])
{
$config['field'] = $this;
// ...
}
}
Looks good to me, want me to make a PR or will you just push the changes directly?
One way or another it is the matter for 2.0.12 and will be considered only after 2.0.11 release.
Resolved by commit 3946ac0dabf3cfce62ed251b89d6b66aa422e3be
Most helpful comment
InputWidgetshould be tied toActiveFieldinstead ofActiveFormasActiveField::$formalready allows getting form from field.