mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-26 11:48:49 +02:00
Improved NumberConstraintType a bit.
This commit is contained in:
parent
f9d945c4c7
commit
f6239dfd50
3 changed files with 36 additions and 7 deletions
|
@ -18,6 +18,14 @@ class NumberConstraintType extends AbstractType
|
||||||
$resolver->setDefaults([
|
$resolver->setDefaults([
|
||||||
'compound' => true,
|
'compound' => true,
|
||||||
'data_class' => NumberConstraint::class,
|
'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',
|
'BETWEEN' => 'BETWEEN',
|
||||||
];
|
];
|
||||||
|
|
||||||
$builder->add('value1', NumberType::class, [
|
$builder->add('value1', NumberType::class, array_merge_recursive([
|
||||||
'label' => 'filter.number_constraint.value1',
|
'label' => 'filter.number_constraint.value1',
|
||||||
'attr' => [
|
'attr' => [
|
||||||
'placeholder' => 'filter.number_constraint.value1',
|
'placeholder' => 'filter.number_constraint.value1',
|
||||||
|
'max' => $options['max'],
|
||||||
|
'min' => $options['min'],
|
||||||
|
'step' => $options['step'],
|
||||||
],
|
],
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'html5' => true,
|
'html5' => true,
|
||||||
]);
|
], $options['value1_options']));
|
||||||
$builder->add('value2', NumberType::class, [
|
|
||||||
|
$builder->add('value2', NumberType::class, array_merge_recursive([
|
||||||
'label' => 'filter.number_constraint.value2',
|
'label' => 'filter.number_constraint.value2',
|
||||||
'attr' => [
|
'attr' => [
|
||||||
'placeholder' => 'filter.number_constraint.value2',
|
'placeholder' => 'filter.number_constraint.value2',
|
||||||
|
'max' => $options['max'],
|
||||||
|
'min' => $options['min'],
|
||||||
|
'step' => $options['step'],
|
||||||
],
|
],
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'html5' => true,
|
'html5' => true,
|
||||||
]);
|
], $options['value2_options']));
|
||||||
|
|
||||||
$builder->add('operator', ChoiceType::class, [
|
$builder->add('operator', ChoiceType::class, [
|
||||||
'label' => 'filter.number_constraint.operator',
|
'label' => 'filter.number_constraint.operator',
|
||||||
'choices' => $choices,
|
'choices' => $choices,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||||
|
{
|
||||||
|
parent::buildView($view, $form, $options);
|
||||||
|
|
||||||
|
$view->vars['text_suffix'] = $options['text_suffix'];
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -33,7 +33,9 @@ class PartFilterType extends AbstractType
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$builder->add('mass', NumberConstraintType::class, [
|
$builder->add('mass', NumberConstraintType::class, [
|
||||||
'label' => 'part.edit.mass'
|
'label' => 'part.edit.mass',
|
||||||
|
'text_suffix' => 'g',
|
||||||
|
'min' => 0,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$builder->add('submit', SubmitType::class, [
|
$builder->add('submit', SubmitType::class, [
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
{% block number_constraint_widget %}
|
{% block number_constraint_widget %}
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
{{ form_widget(form.operator) }}
|
{{ form_widget(form.operator, {"attr": {"class": "form-select"}}) }}
|
||||||
{{ form_widget(form.value1) }}
|
{{ form_widget(form.value1) }}
|
||||||
|
<span class="input-group-text">AND</span>
|
||||||
{{ form_widget(form.value2) }}
|
{{ form_widget(form.value2) }}
|
||||||
|
{% if form.vars["text_suffix"] %}
|
||||||
|
<span class="input-group-text">{{ form.vars["text_suffix"] }}</span>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
Add table
Add a link
Reference in a new issue