How to remove default upload field label? - html

In one of my uploader field, I see a caption displays as the field label which I have failed to change or remove.
Seriously I don't know where it comes from
How to disappear that default label? What to change in my html code? Actually i am using twig php to call the field from an Class object.
profile.html.twig
<div class="row">
<div class="col-md-12 text-center">
<h4>{{user.civilite}} {{ user.nom }} {{ user.prenom }}</h4>
</div>
<div class="col-md-12">
<img class="img-responsive" id="profile-image" src="{{ asset('uploads/profile/images') }}/{{ user.imageprofil }}" alt="">
</div>
</div>
ProfileFormType.php
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('imageProfil')->add('imageFile', VichImageType::class, array('label' => false, 'required' => false ))
->add('civilite', ChoiceType::class, array('choices' => array('M.' => 'M', 'Mme.' => 'Mme'),
'attr' => array(
'class' => 'form-control',
'placeholder' => 'Nom de Famille',
'style' => "margin-bottom:5px;"
)))
->add('nom', TextType::class, array('label' => 'Nom de Famille', 'attr' => array(
'class' => 'form-control',
'placeholder' => 'Nom de Famille',
'style' => "margin-bottom:5px;"
)))
->add('prenom', TextType::class, array('label' => 'Prénom', 'attr' => array(
'class' => 'form-control',
'placeholder' => 'Prénom',
'style' => "margin-bottom:5px;"
)))
->add('email', EmailType::class, array('label' => 'Email', 'attr' => array(
'class' => 'form-control',
'placeholder' => 'Email',
'style' => "margin-bottom:5px;"
)))
Where i can code to disappear the label caption?
i.e. "Aucun fichier choisi"
Solution
<style>
#app_user_profile_imageFile_file {
display: block;
color: transparent;
}
#app_user_profile_imageProfil{
width: 100px;
}
</style>

This is native part of webkit browsers.
You can't remove it the normal way, but you can trick the browser not to show it with little bit of css - just make the font color transparent.
input[type='file'] {
color: transparent;
}

Just add option parameter ['label' => false]

Related

How to render another controller method by image link using yii2?

following code will render an image:
<?= Html::img('#web/img/accept_all_you_see-wallpaper-1680x1050.jpg', ['alt' => 'PicNotFound', 'class' => 'scale-with-grid wp-post-image', 'style' => 'width:960;height:700']); ?>
following code will render an image as a link
<?= Html::a('', Yii::getAlias('#web') . '/img/pic1.jpg', ['target' => '_blank', 'alt' => 'PicNotFound', 'class' => 'icon-search']) ?>
How to code, if I want render another Conroller method by clicking on an image?
Following code will implement my intention by bootstrap icon, not by image!
<div class="col-md-12">
<?= Html::a('<span class="glyphicon glyphicon-paperclip"></span>', ['/dateianhang/dateianhang/index'], ['title' => 'Anlagen anzeigen', 'data' => ['pjax' => '0']]); ?>
</div>
<?= Html::a(
Html::img(
'#web/img/accept_all_you_see-wallpaper-1680x1050.jpg',
['alt' => 'PicNotFound', 'class' => 'scale-with-grid wp-post-image', 'style' => 'width:960;height:700']
),
['/dateianhang/dateianhang/index'],
['title' => 'Anlagen anzeigen', 'data' => ['pjax' => '0']]
) ?>

How to add a placeholder to Select2 Widget - Yii2

I am working a yii2 page and it's giving me problems adding a placeholder or a prompt to Select2 Widget. Here is my code:
<?php
use yii\helpers\Html;
use kartik\widgets\ActiveForm;
use kartik\builder\Form;
use kartik\datecontrol\DateControl;
use yii\helpers\ArrayHelper;
/**
* #var yii\web\View $this
* #var app\models\FinancialAccounts $model
* #var yii\widgets\ActiveForm $form
*/
?>
<div class="financial-accounts-form">
<?php $form = ActiveForm::begin(['type' => ActiveForm::TYPE_VERTICAL]); echo Form::widget([
'model' => $model,
'form' => $form,
'columns' => 1,
'attributes' => [
'type_id' => ['type' => Form::INPUT_WIDGET, 'widgetClass'=>'\kartik\widgets\Select2', 'options' => ['data'=>ArrayHelper::map(app\models\FinancialAccountType::find()->all(), 'type_id', 'name')]],
'account_name' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Account Name...', 'maxlength' => 100]],
'account_code' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Account Code...', 'maxlength' => 10]],
'parent_id' => ['type' => Form::INPUT_WIDGET, 'widgetClass'=>'\kartik\widgets\Select2', 'options' => ['data'=>ArrayHelper::map(app\models\FinancialAccounts::find()->all(), 'account_id', 'account_name'), 'placeholder' => 'Select a Parent Account...']],
'description' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Description...', 'maxlength' => 250]],
],
]);
echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'),
['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']
);
ActiveForm::end(); ?>
</div>
The problem is in the parent_id attribute as I cannot add a placeholder as an option as most of the tutorials recommend. Everytime I try that, I get an error as this:
Unknown Property – yii\base\UnknownPropertyException
Setting unknown property: kartik\widgets\Select2::placeholder
Does anyone know how I can solve this? My main problem is that I cannot leave this option as blank when submitting data yet that is one of the possibility. It forces me to submit an item selected.
You'll note that if you follow the examples in the documentation carefully, placeholder needs to be wrapped within an options array.
'parent_id' => [
'type' => Form::INPUT_WIDGET,
'widgetClass' => '\kartik\widgets\Select2',
'options' => [
'data' => ArrayHelper::map(app\models\FinancialAccounts::find()
->all(), 'account_id', 'account_name'),
'options' => ['placeholder' => '...'],
'pluginOptions' => ['allowClear' => true],
]
],

Remove encoding for popovers on labels

I'm using Yii2 to generate a popover on a label, but having some trouble to remove the default HTML encoding. I'm not sure that the popover can be created for just the label without HTML encoding and what the correct way to do this is, it must be possible though as Gii uses some variant of this code? This is what I've tried:
<?= $form->field($model, 'function')->textInput(['maxlength' => true])
->label(null, [
'class' => 'dashed-line',
'data-toggle' => 'popover',
'data-content' => 'This will be ran through <code>strtolower()</code>',
'data-placement' => 'right',
'encodeLabel'=> false]) ?>
Use
['labelOptions' => ['encode' => false]]
.
<?= $form->field($model, ['labelOptions' => ['encode' => false]] ,
'function')->textInput(['maxlength' => true])
->label(null, [
'class' => 'dashed-line',
'data-toggle' => 'popover',
'data-content' => 'This will be ran through <code>strtolower()</code>',
'data-placement' => 'right',
) ?>
you can use label option for setting the encode false of label attribute
<?= $form->field($model,
'function')->textInput(['maxlength' => true])
->label(null, [
'class' => 'dashed-line',
'data-toggle' => 'popover',
'data-content' => 'This will be ran through <code>strtolower()</code>',
'data-placement' => 'right',
'encode' => false,
) ?>

Yii2 - NavBar widget hyperlink to div

anyone knows how can i in Yii2 using the navbar widget make a hyperlink to a div that is above the 100% height screen and is hidden in order that the screen scrolls down to it?
The code i'm using for the navbar is the standard one that comes with yii in layout.php
['label' => 'Contact', 'url' => ['/site/contact']],
I substitute 'url' => ['/site/contact']], --> by something like 'url' => ['#divid']],
But it doesn't works.
Many thanks in advance for an answer.
Just specify url as a string:
['label' => 'Contact', 'url' => '#divId'],
Url parameter is processed by Url::to() method, you can see there how string is interpreted:
a normal string: it will be returned as is.
Thank you very much for your help, it works. I was trying to do this
<body data-spy="scroll" data-target="#navbar" data-offset="50">
<?php $this->beginBody() ?>
<div class="wrap">
<?php
NavBar::begin([
//'brandLabel' => Yii::$app->name,
'brandLabel' => '<img src="SLOGAN.png" style="display:inline; vertical-align:top; margin-top:20px; margin-left: 10px;"/>',
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar navbar-fixed-top navbar-inverse',
'id'=>'navbar'
],
]);
echo Nav::widget([
'options' => ['class' => 'nav navbar-nav navbar-left'],
'items' => [
['label' => 'HOME', 'url' => '#section1'],
['label' => 'ABOUT', 'url' => '#section2'],
['label' => 'SERVICES', 'url' =>'#section3'],
['label' => 'FAQS', 'url' => '#section4'],
['label' => 'CONTACTS', 'url' => '#section5'],

CakePHP - FormHelper not outputting form tags

I have the following form declaration:
<div class="edit-dialog span-10" style="display:none;">
<div class="edit-message span-10" style="margin-bottom:30px;">
<span>Editing: <a style="text-decoration:none"></a></span>
</div>
<?php
echo $this->Form->create('Voicenote', array('action' => 'edit'));
echo $this->Form->input('title', array(
'div' => false,
'class' => 'input-text recorder',
'label' => array(
'class' => 'inlined',
'text' => ''
),
'id' => 'VoicenoteEditTitle',
'placeholder' => 'Title',
'style' => 'margin-bottom:10px;',
'onsubmit' => 'return false;'
));
echo $this->Form->input('tags', array(
'div' => false,
'class' => 'input-text recorder',
'id' => 'VoicenoteEditTags',
'label' => false,
'placeholder' => 'Tags',
'onsubmit' => 'return false;'
));
echo $this->Form->button('Cancel', array(
'class' => 'button medium blue',
'id' => 'cancel-edit',
'style' => 'float:left;margin-top:50px;'
));
echo $this->Form->submit('Save', array(
'class' => 'button medium blue',
'id' => 'save-edit',
'style' => 'float:right;margin-top:50px;'
));
?>
<input type="hidden" id="edit-container-index" value="">
</div>
It's not outputting the <form></form> tags and I have declared my forms this way throughout my app, adding the $this->Form->end() doesn't work either, any clues?
EDIT: explicitly declaring the <form></form> tags does not output them either
EDIT 2: there is something really weird I'm noticing. I have 4 forms on the page with the problem, If I remove the rendering of the element with the problem, another one of my forms wont render, the one right after it.
you have a submit button. just add end() after submit button in your ctp file.
<?php
echo $this->Form->create('users');
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->submit('login');
echo $this->Form->end();
?>
Hi I think if you change last echo to
echo $this->Form->end( array(
'label'=>'Save',
'class' => 'button medium blue',
'id' => 'save-edit',
'style' => 'float:right;margin-top:50px;'
));
it should work