DatePicker Does Not Respect Form Reset
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have an asp.net form with various textboxes and kendo datepickers. I allow the user to fill in the form and if they decide to start again I have a reset button for them.
The reset button should reset the form to its original model data. To be clear I don't want to reset the form to blank values, I want to reset all the inputs to their original model values.
This works nicely for the textboxes however after hitting the reset button the datepicker simply displays a "d" and not the original model value.
I use the following javascript/jquery to reset the form:
$(this).closest('form')[0].reset();
Here is my extract form code with the datepicker:
<tr>
<td><label asp-for="Aircraft.SerialNumber" class="frm-label"></label></td>
<td>
<input asp-for="Aircraft.SerialNumber" autocomplete="off" class="k-textbox k-state-disabled" style="width:400px" disabled />
<span asp-validation-for="Aircraft.SerialNumber" class="text-danger"></span>
</td>
</tr>
<tr>
<td><label asp-for="Aircraft.ManufactureDate" class="frm-label"></label>
</td>
<td>
<kendo-datepicker name="DatePicker" for="Aircraft.ManufactureDate" class="" style='width: 400px;' />
<span asp-validation-for="Aircraft.ManufactureDate" class="text-danger"></span>
</td>
</tr>
I'm not sure wether this problem lies with the telerik widget or my jquery/javascript code so I have also posted here
javascript jquery asp.net-core kendo-ui telerik
add a comment |
I have an asp.net form with various textboxes and kendo datepickers. I allow the user to fill in the form and if they decide to start again I have a reset button for them.
The reset button should reset the form to its original model data. To be clear I don't want to reset the form to blank values, I want to reset all the inputs to their original model values.
This works nicely for the textboxes however after hitting the reset button the datepicker simply displays a "d" and not the original model value.
I use the following javascript/jquery to reset the form:
$(this).closest('form')[0].reset();
Here is my extract form code with the datepicker:
<tr>
<td><label asp-for="Aircraft.SerialNumber" class="frm-label"></label></td>
<td>
<input asp-for="Aircraft.SerialNumber" autocomplete="off" class="k-textbox k-state-disabled" style="width:400px" disabled />
<span asp-validation-for="Aircraft.SerialNumber" class="text-danger"></span>
</td>
</tr>
<tr>
<td><label asp-for="Aircraft.ManufactureDate" class="frm-label"></label>
</td>
<td>
<kendo-datepicker name="DatePicker" for="Aircraft.ManufactureDate" class="" style='width: 400px;' />
<span asp-validation-for="Aircraft.ManufactureDate" class="text-danger"></span>
</td>
</tr>
I'm not sure wether this problem lies with the telerik widget or my jquery/javascript code so I have also posted here
javascript jquery asp.net-core kendo-ui telerik
add a comment |
I have an asp.net form with various textboxes and kendo datepickers. I allow the user to fill in the form and if they decide to start again I have a reset button for them.
The reset button should reset the form to its original model data. To be clear I don't want to reset the form to blank values, I want to reset all the inputs to their original model values.
This works nicely for the textboxes however after hitting the reset button the datepicker simply displays a "d" and not the original model value.
I use the following javascript/jquery to reset the form:
$(this).closest('form')[0].reset();
Here is my extract form code with the datepicker:
<tr>
<td><label asp-for="Aircraft.SerialNumber" class="frm-label"></label></td>
<td>
<input asp-for="Aircraft.SerialNumber" autocomplete="off" class="k-textbox k-state-disabled" style="width:400px" disabled />
<span asp-validation-for="Aircraft.SerialNumber" class="text-danger"></span>
</td>
</tr>
<tr>
<td><label asp-for="Aircraft.ManufactureDate" class="frm-label"></label>
</td>
<td>
<kendo-datepicker name="DatePicker" for="Aircraft.ManufactureDate" class="" style='width: 400px;' />
<span asp-validation-for="Aircraft.ManufactureDate" class="text-danger"></span>
</td>
</tr>
I'm not sure wether this problem lies with the telerik widget or my jquery/javascript code so I have also posted here
javascript jquery asp.net-core kendo-ui telerik
I have an asp.net form with various textboxes and kendo datepickers. I allow the user to fill in the form and if they decide to start again I have a reset button for them.
The reset button should reset the form to its original model data. To be clear I don't want to reset the form to blank values, I want to reset all the inputs to their original model values.
This works nicely for the textboxes however after hitting the reset button the datepicker simply displays a "d" and not the original model value.
I use the following javascript/jquery to reset the form:
$(this).closest('form')[0].reset();
Here is my extract form code with the datepicker:
<tr>
<td><label asp-for="Aircraft.SerialNumber" class="frm-label"></label></td>
<td>
<input asp-for="Aircraft.SerialNumber" autocomplete="off" class="k-textbox k-state-disabled" style="width:400px" disabled />
<span asp-validation-for="Aircraft.SerialNumber" class="text-danger"></span>
</td>
</tr>
<tr>
<td><label asp-for="Aircraft.ManufactureDate" class="frm-label"></label>
</td>
<td>
<kendo-datepicker name="DatePicker" for="Aircraft.ManufactureDate" class="" style='width: 400px;' />
<span asp-validation-for="Aircraft.ManufactureDate" class="text-danger"></span>
</td>
</tr>
I'm not sure wether this problem lies with the telerik widget or my jquery/javascript code so I have also posted here
javascript jquery asp.net-core kendo-ui telerik
javascript jquery asp.net-core kendo-ui telerik
asked Nov 26 '18 at 20:30
ReafidyReafidy
6,23033372
6,23033372
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I tried with code sample :https://demos.telerik.com/aspnet-core/datepicker/tag-helper
And using :
$("#FormID").trigger("reset");
It can successfully reset datetimepicker to default model value :
<kendo-datepicker name='datepicker'
for="OrderDate"
style='width: 100%;'></kendo-datepicker>
But not work for datetimepicker which set with static value(change to format string) :
<kendo-datepicker name="monthpicker"
start="CalendarView.Year"
depth="CalendarView.Year"
format="MMMM yyyy"
value='DateTime.Parse("November 2011")'
style="width: 100%;"></kendo-datepicker>
But you can always set the value for that(store value form model/viewbag in hidden field) :
$("#monthpicker").val("November 2013")
EDIT :
So as a workaround , you can add hidden field :
<input type="hidden" id="DeOrderDate" asp-for="OrderDate"/>
And then use Jquery to re-bind the value :
$("#FormID").trigger("reset");
$("#OrderDate").data('kendoDatePicker').value($("#DeOrderDate").val())
That should work for special scenario .
Sorry I thought this worked, but there was an error in my testing. Using the code you have provided does the same thing for me it simply resets the datepicker to the value "d" and not the original model value.
– Reafidy
Nov 27 '18 at 6:03
I checked the sample application you suggested and it works as you described. The difference between mine and the sample application is that my model is annotated with[DataType(DataType.Date)]public DateTime ManufactureDate { get; set; }
removing this fixed the problem but I cant figure out why. Also changing the format string to "dd/MM/yyyy" also stuffs it up.
– Reafidy
Nov 27 '18 at 6:13
@Reafidy Not sure , or you can try the workaround as my edited reply
– Nan Yu
Nov 27 '18 at 6:19
Thanks, I'm not sure your workaround is suitable. I have up to 100 datepickers on one page generated dynamically. I will look into it though. It seems when the format is changed the datepicker overrides the "value" attribute with the format so you end up withvalue="dd/MM/yyyy"
. So the reset reverts to this. Seems odd.
– Reafidy
Nov 27 '18 at 6:29
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53488586%2fdatepicker-does-not-respect-form-reset%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I tried with code sample :https://demos.telerik.com/aspnet-core/datepicker/tag-helper
And using :
$("#FormID").trigger("reset");
It can successfully reset datetimepicker to default model value :
<kendo-datepicker name='datepicker'
for="OrderDate"
style='width: 100%;'></kendo-datepicker>
But not work for datetimepicker which set with static value(change to format string) :
<kendo-datepicker name="monthpicker"
start="CalendarView.Year"
depth="CalendarView.Year"
format="MMMM yyyy"
value='DateTime.Parse("November 2011")'
style="width: 100%;"></kendo-datepicker>
But you can always set the value for that(store value form model/viewbag in hidden field) :
$("#monthpicker").val("November 2013")
EDIT :
So as a workaround , you can add hidden field :
<input type="hidden" id="DeOrderDate" asp-for="OrderDate"/>
And then use Jquery to re-bind the value :
$("#FormID").trigger("reset");
$("#OrderDate").data('kendoDatePicker').value($("#DeOrderDate").val())
That should work for special scenario .
Sorry I thought this worked, but there was an error in my testing. Using the code you have provided does the same thing for me it simply resets the datepicker to the value "d" and not the original model value.
– Reafidy
Nov 27 '18 at 6:03
I checked the sample application you suggested and it works as you described. The difference between mine and the sample application is that my model is annotated with[DataType(DataType.Date)]public DateTime ManufactureDate { get; set; }
removing this fixed the problem but I cant figure out why. Also changing the format string to "dd/MM/yyyy" also stuffs it up.
– Reafidy
Nov 27 '18 at 6:13
@Reafidy Not sure , or you can try the workaround as my edited reply
– Nan Yu
Nov 27 '18 at 6:19
Thanks, I'm not sure your workaround is suitable. I have up to 100 datepickers on one page generated dynamically. I will look into it though. It seems when the format is changed the datepicker overrides the "value" attribute with the format so you end up withvalue="dd/MM/yyyy"
. So the reset reverts to this. Seems odd.
– Reafidy
Nov 27 '18 at 6:29
add a comment |
I tried with code sample :https://demos.telerik.com/aspnet-core/datepicker/tag-helper
And using :
$("#FormID").trigger("reset");
It can successfully reset datetimepicker to default model value :
<kendo-datepicker name='datepicker'
for="OrderDate"
style='width: 100%;'></kendo-datepicker>
But not work for datetimepicker which set with static value(change to format string) :
<kendo-datepicker name="monthpicker"
start="CalendarView.Year"
depth="CalendarView.Year"
format="MMMM yyyy"
value='DateTime.Parse("November 2011")'
style="width: 100%;"></kendo-datepicker>
But you can always set the value for that(store value form model/viewbag in hidden field) :
$("#monthpicker").val("November 2013")
EDIT :
So as a workaround , you can add hidden field :
<input type="hidden" id="DeOrderDate" asp-for="OrderDate"/>
And then use Jquery to re-bind the value :
$("#FormID").trigger("reset");
$("#OrderDate").data('kendoDatePicker').value($("#DeOrderDate").val())
That should work for special scenario .
Sorry I thought this worked, but there was an error in my testing. Using the code you have provided does the same thing for me it simply resets the datepicker to the value "d" and not the original model value.
– Reafidy
Nov 27 '18 at 6:03
I checked the sample application you suggested and it works as you described. The difference between mine and the sample application is that my model is annotated with[DataType(DataType.Date)]public DateTime ManufactureDate { get; set; }
removing this fixed the problem but I cant figure out why. Also changing the format string to "dd/MM/yyyy" also stuffs it up.
– Reafidy
Nov 27 '18 at 6:13
@Reafidy Not sure , or you can try the workaround as my edited reply
– Nan Yu
Nov 27 '18 at 6:19
Thanks, I'm not sure your workaround is suitable. I have up to 100 datepickers on one page generated dynamically. I will look into it though. It seems when the format is changed the datepicker overrides the "value" attribute with the format so you end up withvalue="dd/MM/yyyy"
. So the reset reverts to this. Seems odd.
– Reafidy
Nov 27 '18 at 6:29
add a comment |
I tried with code sample :https://demos.telerik.com/aspnet-core/datepicker/tag-helper
And using :
$("#FormID").trigger("reset");
It can successfully reset datetimepicker to default model value :
<kendo-datepicker name='datepicker'
for="OrderDate"
style='width: 100%;'></kendo-datepicker>
But not work for datetimepicker which set with static value(change to format string) :
<kendo-datepicker name="monthpicker"
start="CalendarView.Year"
depth="CalendarView.Year"
format="MMMM yyyy"
value='DateTime.Parse("November 2011")'
style="width: 100%;"></kendo-datepicker>
But you can always set the value for that(store value form model/viewbag in hidden field) :
$("#monthpicker").val("November 2013")
EDIT :
So as a workaround , you can add hidden field :
<input type="hidden" id="DeOrderDate" asp-for="OrderDate"/>
And then use Jquery to re-bind the value :
$("#FormID").trigger("reset");
$("#OrderDate").data('kendoDatePicker').value($("#DeOrderDate").val())
That should work for special scenario .
I tried with code sample :https://demos.telerik.com/aspnet-core/datepicker/tag-helper
And using :
$("#FormID").trigger("reset");
It can successfully reset datetimepicker to default model value :
<kendo-datepicker name='datepicker'
for="OrderDate"
style='width: 100%;'></kendo-datepicker>
But not work for datetimepicker which set with static value(change to format string) :
<kendo-datepicker name="monthpicker"
start="CalendarView.Year"
depth="CalendarView.Year"
format="MMMM yyyy"
value='DateTime.Parse("November 2011")'
style="width: 100%;"></kendo-datepicker>
But you can always set the value for that(store value form model/viewbag in hidden field) :
$("#monthpicker").val("November 2013")
EDIT :
So as a workaround , you can add hidden field :
<input type="hidden" id="DeOrderDate" asp-for="OrderDate"/>
And then use Jquery to re-bind the value :
$("#FormID").trigger("reset");
$("#OrderDate").data('kendoDatePicker').value($("#DeOrderDate").val())
That should work for special scenario .
edited Nov 27 '18 at 6:24
answered Nov 27 '18 at 4:55
Nan YuNan Yu
7,6302864
7,6302864
Sorry I thought this worked, but there was an error in my testing. Using the code you have provided does the same thing for me it simply resets the datepicker to the value "d" and not the original model value.
– Reafidy
Nov 27 '18 at 6:03
I checked the sample application you suggested and it works as you described. The difference between mine and the sample application is that my model is annotated with[DataType(DataType.Date)]public DateTime ManufactureDate { get; set; }
removing this fixed the problem but I cant figure out why. Also changing the format string to "dd/MM/yyyy" also stuffs it up.
– Reafidy
Nov 27 '18 at 6:13
@Reafidy Not sure , or you can try the workaround as my edited reply
– Nan Yu
Nov 27 '18 at 6:19
Thanks, I'm not sure your workaround is suitable. I have up to 100 datepickers on one page generated dynamically. I will look into it though. It seems when the format is changed the datepicker overrides the "value" attribute with the format so you end up withvalue="dd/MM/yyyy"
. So the reset reverts to this. Seems odd.
– Reafidy
Nov 27 '18 at 6:29
add a comment |
Sorry I thought this worked, but there was an error in my testing. Using the code you have provided does the same thing for me it simply resets the datepicker to the value "d" and not the original model value.
– Reafidy
Nov 27 '18 at 6:03
I checked the sample application you suggested and it works as you described. The difference between mine and the sample application is that my model is annotated with[DataType(DataType.Date)]public DateTime ManufactureDate { get; set; }
removing this fixed the problem but I cant figure out why. Also changing the format string to "dd/MM/yyyy" also stuffs it up.
– Reafidy
Nov 27 '18 at 6:13
@Reafidy Not sure , or you can try the workaround as my edited reply
– Nan Yu
Nov 27 '18 at 6:19
Thanks, I'm not sure your workaround is suitable. I have up to 100 datepickers on one page generated dynamically. I will look into it though. It seems when the format is changed the datepicker overrides the "value" attribute with the format so you end up withvalue="dd/MM/yyyy"
. So the reset reverts to this. Seems odd.
– Reafidy
Nov 27 '18 at 6:29
Sorry I thought this worked, but there was an error in my testing. Using the code you have provided does the same thing for me it simply resets the datepicker to the value "d" and not the original model value.
– Reafidy
Nov 27 '18 at 6:03
Sorry I thought this worked, but there was an error in my testing. Using the code you have provided does the same thing for me it simply resets the datepicker to the value "d" and not the original model value.
– Reafidy
Nov 27 '18 at 6:03
I checked the sample application you suggested and it works as you described. The difference between mine and the sample application is that my model is annotated with
[DataType(DataType.Date)]public DateTime ManufactureDate { get; set; }
removing this fixed the problem but I cant figure out why. Also changing the format string to "dd/MM/yyyy" also stuffs it up.– Reafidy
Nov 27 '18 at 6:13
I checked the sample application you suggested and it works as you described. The difference between mine and the sample application is that my model is annotated with
[DataType(DataType.Date)]public DateTime ManufactureDate { get; set; }
removing this fixed the problem but I cant figure out why. Also changing the format string to "dd/MM/yyyy" also stuffs it up.– Reafidy
Nov 27 '18 at 6:13
@Reafidy Not sure , or you can try the workaround as my edited reply
– Nan Yu
Nov 27 '18 at 6:19
@Reafidy Not sure , or you can try the workaround as my edited reply
– Nan Yu
Nov 27 '18 at 6:19
Thanks, I'm not sure your workaround is suitable. I have up to 100 datepickers on one page generated dynamically. I will look into it though. It seems when the format is changed the datepicker overrides the "value" attribute with the format so you end up with
value="dd/MM/yyyy"
. So the reset reverts to this. Seems odd.– Reafidy
Nov 27 '18 at 6:29
Thanks, I'm not sure your workaround is suitable. I have up to 100 datepickers on one page generated dynamically. I will look into it though. It seems when the format is changed the datepicker overrides the "value" attribute with the format so you end up with
value="dd/MM/yyyy"
. So the reset reverts to this. Seems odd.– Reafidy
Nov 27 '18 at 6:29
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53488586%2fdatepicker-does-not-respect-form-reset%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown