0

Just starting to learn the Yii. I do not know how to change the button and remove the "No files selected" in the widget "CMultiFileUpload" in Yii framework?

$this->widget('CMultiFileUpload', array(
    'model'=>$model,
    'attribute'=>'photos',
    'accept'=>'jpg|jpeg|gif|png',
    'name'=>'photos',
    'remove'=>'remove',
    'options'=>array(
    ),
    'denied'=>'File is not allowed',
    'max'=>4, // max 10 files
));
user3380172
  • 37
  • 2
  • 9

1 Answers1

-1

This is browser dependent. Ex. Mozilla shows the input file type field with "No files selected". In IE it will come defferently.

If you want to hide the message "No files selected", do it with CSS

input[type='file'] 
{
    color: transparent;
}

If you want to customize more, Try this bellow code.

  1. Add this CSS code in your CSS file

    #multFileUpload button#fileAlt
    {
        border: 3px solid #cccccc;
        background-color: #FF7B10 !important;
        color: #ffffff;
        font-size: 14px;
        padding: 10px 5px;        
        cursor: pointer;
        border-radius: 5px;
        -moz-border-radius: 5px;
        -webkit-border-radius: 5px;
    }
    #multFileUpload input[type='file'] 
    {
        display: none;
    }    
    
  2. Add this jQuery code in your javascript file

    $(document).ready(function()
    {
        var maxFiles = 4;
        var fileCountStart = 0;
        $("#fileAlt").on('click', function()
        {
            fileCountStart += 1;
            if (maxFiles >= fileCountStart)
            {
                $('#photos').trigger('click');
                if (fileCountStart == maxFiles)
                    $("#fileAlt").attr('disabled', 'disabled');
            }
        });
    });
    
  3. Now Yii code

    <div id="multFileUpload">
        <button id="fileAlt">Select an Image</button>
        <?php            
        $this->widget('CMultiFileUpload', array(
            'model' => $model,
            'id'=>'photos',
            'attribute' => 'photos',
            'accept' => 'jpg|jpeg|gif|png',
            'name' => 'photos',
            'remove' => 'remove',
            'options' => array(
            ),
            'denied' => 'File is not allowed',
            'max' => 4, // max 10 files
        ));
        ?>
    </div>
    
Hearaman
  • 8,466
  • 13
  • 41
  • 58
  • Thx. I removed the label "No file selected". When How can I change text in a button? When I adding I have two buttons, but I need one. – user3380172 May 02 '14 at 11:06
  • Perhaps you did not add css i gave. Keep it in your css file then original button will be hidden – Hearaman May 02 '14 at 12:00