如何在我的 Formbuilder (Symfony 4) 中使用占位符?
How can I use a placeholder in my Formbuilder (Symfony 4)?
我想为我的密码字段使用占位符(如果它不为空):
$formBuilder->add('plainPassword', PasswordType::class, array('attr' => array('class' => 'form-control'), 'label' => 'Password','placeholder' => '...',));
但我收到一条错误消息:
The option "placeholder" does not exist. Defined options are:
"action", "allow_extra_fields", "always_empty", "attr",
"auto_initialize", "block_name", "by_reference", "compound",
"constraints", "csrf_field_name", "csrf_message", "csrf_protection",
"csrf_token_id", "csrf_token_manager", "data", "data_class",
"disabled", "empty_data", "error_bubbling", "error_mapping",
"extra_fields_message", "help", "inherit_data", "invalid_message",
"invalid_message_parameters", "label", "label_attr", "label_format",
"mapped", "method", "post_max_size_message", "property_path",
"required", "translation_domain", "trim", "upload_max_size_message",
"validation_groups".
如何创建占位符?
您必须像这样将占位符选项放入 attr 数组:
$formBuilder
->add('plainPassword', PasswordType::class, array(
'attr' => array(
'class' => 'form-control',
'placeholder' => '...',
),
'label' => 'Password',
));
你也可以使用类似的东西将它直接放在你的树枝文件中
{{form.widget("password", {'attr':{'placeholder':"password placeholder here"}})}}。当您需要本地占位符时,这会很有用。
我想为我的密码字段使用占位符(如果它不为空):
$formBuilder->add('plainPassword', PasswordType::class, array('attr' => array('class' => 'form-control'), 'label' => 'Password','placeholder' => '...',));
但我收到一条错误消息:
The option "placeholder" does not exist. Defined options are: "action", "allow_extra_fields", "always_empty", "attr", "auto_initialize", "block_name", "by_reference", "compound", "constraints", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_token_id", "csrf_token_manager", "data", "data_class", "disabled", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "help", "inherit_data", "invalid_message", "invalid_message_parameters", "label", "label_attr", "label_format", "mapped", "method", "post_max_size_message", "property_path", "required", "translation_domain", "trim", "upload_max_size_message", "validation_groups".
如何创建占位符?
您必须像这样将占位符选项放入 attr 数组:
$formBuilder
->add('plainPassword', PasswordType::class, array(
'attr' => array(
'class' => 'form-control',
'placeholder' => '...',
),
'label' => 'Password',
));
你也可以使用类似的东西将它直接放在你的树枝文件中 {{form.widget("password", {'attr':{'placeholder':"password placeholder here"}})}}。当您需要本地占位符时,这会很有用。