Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Bernardo Dias da Cruz

Editar visual do input file

Recommended Posts

Olá a todos, eu procurei de diversas formas descobrir como editar o visual de um campo de formulário do tipo FILE, mas não consegui, gostaria de saber se alguem sabe como faz.

 

Estou querendo fazer o seguinte: no lugar do botão do input, quero colocar uma imagem, e no formulário um estilo.

 

Isso parece ser bizarro, porque não consegui encontrar solução em lugar nenhum. Chegam a oferecer até mesmo flash..

 

Bom, desde já agradeço se puderem me ajudar.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Olá,

 

Amigo não sei se este exemplo lhe serve: Link

 

Cumps \o/

Compartilhar este post


Link para o post
Compartilhar em outros sites

Olá,

 

Peço desculpa, não tinha percebido que era do file :P.

Aguarde uma resposta, talvez alguém saiba ;).

 

Cumps \o/

Compartilhar este post


Link para o post
Compartilhar em outros sites

hehehe melhor ainda, da pra usar os dois juntos, digamos, o primeiro funciona melhor, pois ele usa a imagem diretamente no botão do input file, ai não tem bagunça de um sobre o outro usando position: aboslute, coisa que dependendo do caso nao dá.. entao voce coloca um outro input text com usando as funções de onKeyUp e onMouseOut no input file chamando a função js que irá inserir o valor do file no text.. simples..

 

o unico defeito é que usando a tecla tab, você pode focar no campod e texto do input oculto.. e digitar.. hehehe mas fora isso, funciona bem..

 

ótima gambiarra!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Olá,

 

Fico feliz por ter resolvido seu problema e ter postado para posterior ajuda para outros utilizadores. É esse o espirito ;).

Força ai.

 

Cumps \o/

Compartilhar este post


Link para o post
Compartilhar em outros sites

Bom, tambem estou com esse problema e resolvi com o primeiro link, mas o segundo nao quer abrir e nao consigo colocar o valor em um input text alguem podeme ajudar?

Compartilhar este post


Link para o post
Compartilhar em outros sites

hahaha eu sei uma forma com javascript ..

 

joga esse Script aee e não esquece de estar chamando o JQuery!

(function($){$.fn.bootstrapFileInput=function(){this.each(function(i,elem){var $elem=$(elem);if(typeof $elem.attr('data-bfi-disabled')!='undefined'){return;}
var buttonWord='Enviar curriculo';if(typeof $elem.attr('title')!='undefined'){buttonWord=$elem.attr('title');}
var className='';if(!!$elem.attr('class')){className=' '+$elem.attr('class');}
$elem.wrap('<a class="file-input-wrapper btn btn-default '+className+'"></a>').parent().prepend($('<span></span>').html(buttonWord));}).promise().done(function(){$('.file-input-wrapper').mousemove(function(cursor){var input,wrapper,wrapperX,wrapperY,inputWidth,inputHeight,cursorX,cursorY;wrapper=$(this);input=wrapper.find("input");wrapperX=wrapper.offset().left;wrapperY=wrapper.offset().top;inputWidth=input.width();inputHeight=input.height();cursorX=cursor.pageX;cursorY=cursor.pageY;moveInputX=cursorX-wrapperX-inputWidth+20;moveInputY=cursorY-wrapperY-(inputHeight/2);input.css({left:moveInputX,top:moveInputY});});$('body').on('change','.file-input-wrapper input[type=file]',function(){var fileName;fileName=$(this).val();$(this).parent().next('.file-input-name').remove();if(!!$(this).prop('files')&&$(this).prop('files').length>1){fileName=$(this)[0].files.length+' files';}
else{fileName=fileName.substring(fileName.lastIndexOf('\\')+1,fileName.length);}
if(!fileName){return;}
var selectedFileNamePlacement=$(this).data('filename-placement');if(selectedFileNamePlacement==='inside'){$(this).siblings('span').html(fileName);$(this).attr('title',fileName);}else{$(this).parent().after('<span class="file-input-name">'+fileName+'</span>');}});});};var cssHtml='<style>'+'.file-input-wrapper { overflow: hidden; position: relative; cursor: pointer; z-index: 1; }'+'.file-input-wrapper input[type=file], .file-input-wrapper input[type=file]:focus, .file-input-wrapper input[type=file]:hover { position: absolute; top: 0; left: 0; cursor: pointer; opacity: 0; filter: alpha(opacity=0); z-index: 99; outline: 0; }'+'.file-input-name { margin-left: 8px; }'+'</style>';$('link[rel=stylesheet]').eq(0).before(cssHtml);})(jQuery);

Compartilhar este post


Link para o post
Compartilhar em outros sites

Depois de adicionar esse código, seu input file vai ficar como uma estrutura possível de manipular com CSS, basta inspecionar o elemento e verá como estiliza-lo.

 

Espero te ajudado ! =D

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.