Improved NumberConstraintType a bit.

This commit is contained in:
Jan Böhmer 2022-08-15 01:32:09 +02:00
parent f9d945c4c7
commit f6239dfd50
3 changed files with 36 additions and 7 deletions

View file

@ -18,6 +18,14 @@ class NumberConstraintType extends AbstractType
$resolver->setDefaults([
'compound' => true,
'data_class' => NumberConstraint::class,
'text_suffix' => '', // An suffix which is attached as text-append to the input group. This can for example be used for units
'min' => null,
'max' => null,
'step' => 'any',
'value1_options' => [], // Options for the first value input
'value2_options' => [], // Options for the second value input
]);
}
@ -33,25 +41,40 @@ class NumberConstraintType extends AbstractType
'BETWEEN' => 'BETWEEN',
];
$builder->add('value1', NumberType::class, [
$builder->add('value1', NumberType::class, array_merge_recursive([
'label' => 'filter.number_constraint.value1',
'attr' => [
'placeholder' => 'filter.number_constraint.value1',
'max' => $options['max'],
'min' => $options['min'],
'step' => $options['step'],
],
'required' => false,
'html5' => true,
]);
$builder->add('value2', NumberType::class, [
], $options['value1_options']));
$builder->add('value2', NumberType::class, array_merge_recursive([
'label' => 'filter.number_constraint.value2',
'attr' => [
'placeholder' => 'filter.number_constraint.value2',
'max' => $options['max'],
'min' => $options['min'],
'step' => $options['step'],
],
'required' => false,
'html5' => true,
]);
], $options['value2_options']));
$builder->add('operator', ChoiceType::class, [
'label' => 'filter.number_constraint.operator',
'choices' => $choices,
]);
}
public function buildView(FormView $view, FormInterface $form, array $options)
{
parent::buildView($view, $form, $options);
$view->vars['text_suffix'] = $options['text_suffix'];
}
}

View file

@ -29,11 +29,13 @@ class PartFilterType extends AbstractType
]);
$builder->add('needsReview', BooleanConstraintType::class, [
'label' => 'part.edit.needs_review'
'label' => 'part.edit.needs_review'
]);
$builder->add('mass', NumberConstraintType::class, [
'label' => 'part.edit.mass'
'label' => 'part.edit.mass',
'text_suffix' => 'g',
'min' => 0,
]);
$builder->add('submit', SubmitType::class, [

View file

@ -1,7 +1,11 @@
{% block number_constraint_widget %}
<div class="input-group">
{{ form_widget(form.operator) }}
{{ form_widget(form.operator, {"attr": {"class": "form-select"}}) }}
{{ form_widget(form.value1) }}
<span class="input-group-text">AND</span>
{{ form_widget(form.value2) }}
{% if form.vars["text_suffix"] %}
<span class="input-group-text">{{ form.vars["text_suffix"] }}</span>
{% endif %}
</div>
{% endblock %}