2016-04-15 44 views
0

我在產品視圖自定義選項中添加了兩個單選按鈕。和一個依賴於單選按鈕的文本輸入欄。所以當第一個廣播是檢查第一個文本是隱藏的,我添加這個字符:「-------」輸入文本的值屬性。當第二個單選按鈕被選中時,我需要顯示文本輸入字段並刪除值「-------」。Magento自定義選項 - 清除輸入字段問題

要將值添加到文字輸入使用JavaScript: jQuery(".product-options dd input.input-text").attr('value', '--------');

要刪除值我用:jQuery(".product-options dd input.input-text").attr('value', '');

一切正常,直到按添加到購物車按鈕,當我按下添加到購物車按鈕我有這樣的:"Please specify the product's required option(s)."

我的代碼是:

if (jQuery('.product-options .display ul li:nth-child(1)').find('input').is(':checked')) { 
         jQuery(".product-options dd input.input-text").attr('value', '--------'); 
         jQuery(".product-options dd input.input-text").addClass('validation-passed'); 
} 

jQuery('.product-options .display ul li:nth-child(1)').find('input').change(function(){ 
    if (jQuery(this).is(':checked')) { 
         jQuery(".product-options dd input.input-text").attr('value', '--------'); 
         jQuery(".product-options dd input.input-text").addClass('validation-passed'); 
    } 
}) 

jQuery('.product-options .display ul li:nth-child(2)').find('input').change(function(){ 
    if (jQuery(this).is(':checked')) { 
      jQuery(".product-options dd input.input-text").attr('value', ''); 
    } 
}) 

所以我想要的是當第一個廣播被檢查並且輸入文本字段被隱藏以通過驗證並且當第二個廣播被檢查並且文本輸入字段被顯示時移除該值時將該默認值添加到文本輸入字段。

謝謝

+0

變化'.attr( '值', '--------');'在你的第二個變化事件的人 – madalinivascu

+0

謝謝madalin ivascu,但我不很瞭解 – Robert

+0

你不明白什麼? – madalinivascu

回答

1

我最近使用了同樣的事情...(產品選項擴展名)

我的建議是 確保「產品選項DD input.input文本」這是靶向特定元素

  1. 嘗試使用jQuery('.product-options dd input.input-text').val('-------');,因爲它適當的方式到處獲得一致的行爲,工作正確。

  2. 而不是添加一個新類刪除"validate-one-required-by-name"或您添加了驗證的任何magento默認類。

+0

嗨,謝謝你的回答,當我使用這個.val('-------');對於第一臺收音機,我有這個錯誤:文字很長。 – Robert