设置占位符并重命名“浏览”按钮

问题描述 投票:1回答:1

我在Bootstrap中将Vich Uploader捆绑软件用于SF 4.0。我想设置一个占位符并重命名“浏览”按钮。

我已经尝试过:

  • 使用'placehoder'属性(FormType.php)
{{ form_widget(form.imageFile, { 'attr': {'class': 'form-control', 'placeholder': "Please attach picture"}} ) }}
  • 添加'占位符'选项(错误)或标签选项(不进行任何更改)

我该怎么做?

[请在下面找到我的代码

FormType.php

->add('imageFile', VichFileType::class, [])

_ form.html.twig

{{ form_widget(form.imageFile, { 'attr': {'class': 'form-control'}} ) }}
{{ form_errors(form.imageFile) }}
symfony4 vichuploaderbundle
1个回答
0
投票

我假设您正在使用引导程序4;我使用webpack重新编译bootstrap以适应我的需要,并在包含bootstrap.scss之前添加了此scss代码:

$custom-file-text: (
        en: "Browse",
        it: "Sfoglia"
);

// Bootstrap and its default variables
@import "../node_modules/bootstrap/scss/bootstrap";

这样,我可以翻译或更改文件上传按钮。您可以使用此方法个性化Bootstrap的其他方面,请参见Bootstrap online documentation

如果不使用webpack,则应在包含引导css之后添加此css以获得相同的结果

.custom-file-input:lang(en) ~ .custom-file-label::after {
  content: "Browse";
}

.custom-file-input:lang(it) ~ .custom-file-label::after {
  content: "Sfoglia";
}

Symfony 4应用程序支持的每种语言都需要输入一个条目

© www.soinside.com 2019 - 2024. All rights reserved.