Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [jQuery/jqtransform] Dodanie do kodu stylu inputa
einter-project
post
Post #1





Grupa: Zarejestrowani
Postów: 39
Pomógł: 0
Dołączył: 9.09.2011

Ostrzeżenie: (10%)
X----


Witam

Na stronie muszę zastosować ostylowane formularze. Problem w tym że jest kilka styli tych samych pól formularza. Grafika poniosło.

W jaki sposób przekazać styl z pola do funkcji (korzystam z jqtransform):

Na przykład pole input
<input class="searchInput" type="text" name="searchAccommodation" value="">

I teraz chciałbym nazwę klasy wsadzić w:
$input.addClass("jqTransformInput").wrap('<div class="jqTransformInputWrapper_tutaj nazwe klasy"><div class="jqTransformInputInner"><div></div></div></div>');

  1.  
  2. /***************************
  3. Text Fields
  4. ***************************/
  5. $.fn.jqTransInputText = function(){
  6. return this.each(function(){
  7. var $input = $(this);
  8.  
  9. if($input.hasClass('jqtranformdone') || !$input.is('input')) {return;}
  10. $input.addClass('jqtranformdone');
  11.  
  12. var oLabel = jqTransformGetLabel($(this));
  13. oLabel && oLabel.bind('click',function(){$input.focus();});
  14.  
  15. var inputSize=$input.width();
  16. if($input.attr('size')){
  17. inputSize = $input.attr('size')*10;
  18. $input.css('width',inputSize);
  19. }
  20.  
  21. $input.addClass("jqTransformInput").wrap('<div class="jqTransformInputWrapper_tutaj nazwe klasy"><div class="jqTransformInputInner"><div></div></div></div>');
  22. var $wrapper = $input.parent().parent().parent();
  23. $wrapper.css("width", inputSize+10);
  24. $input
  25. .focus(function(){$wrapper.addClass("jqTransformInputWrapper_focus");})
  26. .blur(function(){$wrapper.removeClass("jqTransformInputWrapper_focus");})
  27. .hover(function(){$wrapper.addClass("jqTransformInputWrapper_hover");},function(){$wrapper.removeClass("jqTransformInputWrapper_hover");})
  28. ;
  29.  
  30. /* If this is safari we need to add an extra class */
  31. $.browser.safari && $wrapper.addClass('jqTransformSafari');
  32. $.browser.safari && $input.css('width',$wrapper.width()+16);
  33. this.wrapper = $wrapper;
  34.  
  35. });
  36. };
  37.  


Bardzo prosiłbym o pomoc jak to rozwiązać.
Go to the top of the page
+Quote Post
mortus
post
Post #2





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

Ostrzeżenie: (0%)
-----


Może wystarczy w linii 8 takie coś:
[JAVASCRIPT] pobierz, plaintext
  1. var $inputClass = $input.attr('class');
[JAVASCRIPT] pobierz, plaintext

I później w linii 21:
[JAVASCRIPT] pobierz, plaintext
  1. $input.addClass("jqTransformInput").wrap('<div class="jqTransformInputWrapper_'+$inputClass+'"><div class="jqTransformInputInner"><div></div></div></div>');
[JAVASCRIPT] pobierz, plaintext

Gdyby nie zadziałało to spróbuj jeszcze argument funkcji wrap "ustawić" wcześniej, tj. w linii 20:
[JAVASCRIPT] pobierz, plaintext
  1. var wrapDOM = '<div class="jqTransformInputWrapper_'+$inputClass+'"><div class="jqTransformInputInner"><div></div></div></div>';
  2. $input.addClass("jqTransformInput").wrap(wrapDOM);
[JAVASCRIPT] pobierz, plaintext
Go to the top of the page
+Quote Post
einter-project
post
Post #3





Grupa: Zarejestrowani
Postów: 39
Pomógł: 0
Dołączył: 9.09.2011

Ostrzeżenie: (10%)
X----


Dzięki serdeczne, dla potomnych zmiany w linii 8 i 20, a potem oczywiście trzeba dostosować style do każdej klasy, ale to już nie problem.

Pozdrawiam i jeszcze raz dziękuje za pomoc.


Jeszcze jedno. Mam problem z polem checkbox. Muszę w nim zastosować obsługę funkcji onclick="customerInvoiceVat()". Niestety jak dam onclick to przeładowuje mi stronę, czy jest jakiś sposób aby nie przeładował strony jak się zaznacza to pole.

Pole checkbox;
<input class="RegistrationCheckbox" name="formRegistrationFV" value="1" onclick="customerInvoiceVat()" type="checkbox">

Kawałek kodu odpowiedzialny za to pole:
  1. /***************************
  2. Check Boxes
  3. ***************************/
  4. $.fn.jqTransCheckBox = function(){
  5. return this.each(function(){
  6. if($(this).hasClass('jqTransformHidden')) {return;}
  7.  
  8. var $input = $(this);
  9. var inputSelf = this;
  10. var $inputClass = $input.attr('class');
  11.  
  12. //set the click on the label
  13. var oLabel=jqTransformGetLabel($input);
  14. oLabel && oLabel.click(function(){aLink.trigger('click');});
  15.  
  16. var aLink = $('<a href="#" class="jqTransformCheckbox'+$inputClass+'"></a>');
  17. //wrap and add the link
  18. $input.addClass('jqTransformHidden').wrap('<span class="jqTransformCheckboxWrapper'+$inputClass+'"></span>').parent().prepend(aLink);
  19. //on change, change the class of the link
  20. $input.change(function(){
  21. this.checked && aLink.addClass('jqTransformChecked') || aLink.removeClass('jqTransformChecked');
  22. return true;
  23. });
  24. // Click Handler, trigger the click and change event on the input
  25. aLink.click(function(){
  26. //do nothing if the original input is disabled
  27. if($input.attr('disabled')){return false;}
  28. //trigger the envents on the input object
  29. $input.trigger('click').trigger("change");
  30. return false;
  31. });
  32.  
  33. // set the default state
  34. this.checked && aLink.addClass('jqTransformChecked');
  35. });
  36. };


Pozdrawiam
Go to the top of the page
+Quote Post
mortus
post
Post #4





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

Ostrzeżenie: (0%)
-----


Teoretycznie kliknięcie checkbox-a nie powinno powodować przeładowania strony. Nie widzę również żadnych modyfikacji jqTransform, które mogłyby stwarzać problemy. Winę zatem może ponosić funkcja customerInvoiceVat(). Spróbuj zmodyfikować html tego checkbox-a tak:
  1. <input class="RegistrationCheckbox" name="formRegistrationFV" value="1" onclick="customerInvoiceVat(); return false;" type="checkbox" />

Jeśli to nie pomoże, to trzeba będzie prześledzić kod wspomnianej funkcji.
Go to the top of the page
+Quote Post
einter-project
post
Post #5





Grupa: Zarejestrowani
Postów: 39
Pomógł: 0
Dołączył: 9.09.2011

Ostrzeżenie: (10%)
X----


Dzięki za pomoc, ale jak dodałem poniżej pola input problem zniknął. Za to pojawił się nowy którego już nie wiem jak rozwiązać. Jak zaznaczę pole formRegistrationFV skrypt powinien zrobić aktywne poniżej pola. Bez jqtransform wszystko działa jak ma działać. Jak dodam tylko jqtransform to skrypt reaguje po 2 kliku i działa na odwrót.

  1. <script type="text/javascript">
  2. function customerInvoiceVat() {
  3. var chkAll = document.getElementById('formRegistrationFV');
  4.  
  5. if(chkAll.checked == true){
  6. document.registration.formInvoiceCompany.disabled = false;
  7. document.registration.formInvoiceCompany.className = 'RegistrationInput';
  8. document.getElementById('ID_invoiceCompany').className = 'text';
  9.  
  10. document.registration.formInvoiceName.disabled = false;
  11. document.registration.formInvoiceName.className = 'RegistrationInput';
  12. document.getElementById('ID_invoiceName').className = 'text';
  13.  
  14.  
  15. } else {
  16. document.registration.formInvoiceCompany.disabled = true;
  17. document.registration.formInvoiceCompany.className = 'RegistrationInputNot';
  18. document.getElementById('ID_invoiceCompany').className = 'textNot';
  19.  
  20. document.registration.formInvoiceName.disabled = true;
  21. document.registration.formInvoiceName.className = 'RegistrationInputNot';
  22. document.getElementById('ID_invoiceName').className = 'textNot';
  23. }
  24. }
  25.  
  26. window.onload = customerInvoiceVat;
  27.  


Link do strony: http://31.178.13.71/ogloszenia/customerPan...ateRegistration
Jak rozwiązać aby działał za pierwszym klikiem i nie na odwrót?

Pozdrawiam
Go to the top of the page
+Quote Post
mortus
post
Post #6





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

Ostrzeżenie: (0%)
-----


Szczerze przyznam, że tego błędu też być nie powinno. Z ciekawości przetestowałem prostą funkcję podpiętą do zdarzenia onclick checkbox-a na czystej instalacji jqTransform i wszystko działało tak, jak powinno. Wygląda na to, że ten bałagan w kodzie Twojej strony jest tutaj głównym winowajcą. Radzę przepisać HTML od nowa.

Naiwnym rozwiązaniem problemu może być zamiana true na false w 5 linii funkcji customerInvoiceVat(), jednak nie polecam tego rozwiązania i uważam, że o wiele lepiej będzie, jeśli uporządkujesz kod.

Ten post edytował mortus 18.12.2011, 22:34:12
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 6.10.2025 - 07:51