Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Adjust input following rules #65

Closed
Mister-42 opened this issue Dec 30, 2020 · 8 comments
Closed

[Feature Request] Adjust input following rules #65

Mister-42 opened this issue Dec 30, 2020 · 8 comments

Comments

@Mister-42
Copy link
Contributor

Mister-42 commented Dec 30, 2020

What steps will reproduce the problem?

    public function rules(): array
    {
        return [
            'amount' => [(new Number())->integer()->min(1)->max(250)],
        ];
    }
echo $field->config($form, 'amount')->input('number');

Below is just 1 example, there are probably more validators that can be integrated into the fields.

What is the expected result?

<input type="number" id="form-amount" class="form-control" name="Form[amount]" max="250" min="1" placeholder="Amount">

What do you get instead?

<input type="number" id="form-amount" class="form-control" name="Form[amount]" placeholder="Amount">

Additional info

Q A
Version dev
PHP version 8.0.0
Operating system Debian 10
@Mister-42 Mister-42 changed the title ] [Feature Request] Adjust inout following rules Dec 30, 2020
@Mister-42 Mister-42 changed the title [Feature Request] Adjust inout following rules [Feature Request] Adjust input following rules Dec 30, 2020
@xepozz
Copy link
Member

xepozz commented Jan 8, 2021

I've made a quick draft for that.
Example for configuring form and final html

@Mister-42
Copy link
Contributor Author

Thank you!
This seem to be working with Field::widget, but not $field->config. Is this correct?

@samdark samdark reopened this Jan 24, 2021
@xepozz
Copy link
Member

xepozz commented Jan 25, 2021

Could you please make a test case and show what isn't working?

@Mister-42
Copy link
Contributor Author

Not quickly, but you can use the yii-demo as a reference. For example on the contact page:

<div class="form-group field-contactform-name mb-3">
<label class="control-label form-label control-label required" for="contactform-name">Name</label>
<input type="text" id="contactform-name" class="form-control" name="ContactForm[name]" value="" placeholder="Name" data-cip-id="contactform-name">

<div class="help-block text-danger fst-italic"></div>
</div>

Required is missing from the input.

@xepozz
Copy link
Member

xepozz commented Jan 25, 2021

To enable html attributes you should wrap rules with html options provider decorators.
See yiisoft/demo#229

@Mister-42
Copy link
Contributor Author

To enable html attributes you should wrap rules with html options provider decorators.
See yiisoft/yii-demo#229

Ah alrighty. Not very intuitive to be honest. But if it works... cool!

@samdark samdark closed this as completed Jan 25, 2021
@Mister-42
Copy link
Contributor Author

Mister-42 commented Jan 25, 2021

textarea can have minlength and maxlength
Required is also available for select, textarea
Besides number and email, input can also be url (among other things, but those do not have a validator in Yii. Not sure if that would be viable to implement).


Need more research:

pattern vs RegularExpression Already taken care of, I totally missed that :)
step - not a validation option in Yii

@samdark
Copy link
Member

samdark commented Jan 25, 2021

@Mister-42 extra enhancements could be added separately. Regex is already handled. The rest looks interesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants