मेरे पास सभी पृष्ठों में कैलेंडर का उपयोग करने के लिए वैश्विक रूप से एक Jquery UI Datepicker फ़ंक्शन है। मैं तो बस मेरे विचार में मेरे datepicker क्षेत्र पोस्ट,जावास्क्रिप्ट फ़ंक्शन jquery-AJAX रेल सत्यापन सत्यापन त्रुटि में काम नहीं कर रहा है
<div class="field">
<%= f.label :Renewal_Date %>
<%= f.text_field :Renewal_Date, readonly: 'readonly', data: {field_type: date}}
</div>
मैं एक अलग जावास्क्रिप्ट फाइल करने के लिए ऊपर फ़ंक्शन को कॉल
var showDatePickers = function() {
$('[data-field-type="date"]').datepicker({
dateFormat: "yy-mm--dd",
showOn: "both",
buttonImageOnly: true,
buttonImage: "/assets/blue-calendar-icon.png",
buttonText: "Calendar"
});
}
$(showDatePickers);
: मैं निम्नलिखित की तरह एक अलग जावास्क्रिप्ट पृष्ठ बनाया।
$(function() {
if ($('html.asset_contracts').length == 1) {
$(document.body).on('ajax:success', '.new_asset_contract, .edit_asset_contract', showDatePickers);
}
});
पृष्ठ लोड होने, संपादित करने और नई कार्रवाई के समय यह ठीक काम कर रहा है। लेकिन जब रेल सत्यापन त्रुटि त्रुटि दिनांकक काम करता है तो काम नहीं कर रहा है। यह खाली text_field
दिखा रहा है।
एफवाईआई: यह एक अजाक्स पृष्ठ है और new, create, update and edit
कार्रवाई ajax
पृष्ठों के रूप में काम कर रही है। तो, मैं अपने फार्म में remote: true
जोड़ा गया है और मैं new.js, edit.js, create.js and update.js
यह मेरी नियंत्रक है है,
def create
@contract = Asset::Contract.new(params[:asset_contract])
respond_to do |format|
if @contract.save
format.html { redirect_to asset_contracts_path, notice: "Successfully Created" }
format.js
format.json { render json: @contract, status: :created, location: @contract }
else
format.html { render action: "new" }
format.js
format.json { render json: @contract.errors, status: :unprocessable_entity }
end
end
end
def update
@contract = Asset::Contract.find(params[:id])
respond_to do |format|
if @contract.update_attributes(params[:asset_contract])
format.html { redirect_to asset_contracts_path, notice: "Succesfully Updated" }
format.js
format.json { head :no_content }
else
format.html { render action: "edit" }
format.js
format.json { render json: @contract.errors, status: :unprocessable_entity }
end
end
end
धन्यवाद
जब सत्यापित करता त्रुटि, हो js जाँच datetime क्षेत्र seletor '[डेटा मैदान प्रकार =" date "]' – yxf