In custom ajaxcontroltoolkit (1): Make a calendarextender correspond to the end of N textbox. to display the topic, I pasted one. Maybe you noticed that there is a "clear" button in the lower right corner, this is the change described in this article.
In our project, most input date text boxes are not allowed to be manually input. You can only select a date by clicking the -- pop-up date selection box to avoid annoying check actions, of course, you can also use maskededit for filtering, but it doesn't feel necessary. If you have a date control, it won't be that complicated. In addition, most of the Code in the project was previously written, and no maskededit was available at the time, the read-only method has been used to restrict the date text box.
Because the text box is read-only, once a user selects a date, the text box cannot be blank. In most cases, this is not a problem, but in a few pages, this is quite annoying, more importantly, the previous controls have this function, and the user is used to this operation. Now, I suddenly tell the user that you cannot clear it, which is not very convincing. In addition, from the perspective of system design, the text box is originally allowed to be empty, and by default It is empty. After the date is selected, it will no longer be able to restore it to the null state, it's not easy to say.
Therefore, I think it is necessary to add the clear function to the calendarextender so that it can clear the target text box.
The clear action is very simple, but it is tricky to display it correctly. First, you need to know how to display the calendarbehavior class: first, there is a _ popupdiv attribute, which is the carrier of the entire control, and other controls are attached to this div; the "today" section at the bottom is directly attached to the total carrier _ popupdiv, because there is only one control at the bottom, of course, it can do this, but now you need to add a button to the right of it, you need to change this behavior: Add a _ footer layer as the carrier of the control at the bottom, and append the today date as the Child control to _ footer, add a _ clearbutton control and attach it to _ footer. the code for implementing this process is as follows:
1. Add private attributes:
This. _ clearbutton = NULL;
This. _ footer = NULL;
2. In the _ buildfooter method, rewrite the _ today display mode:
_ Buildfooter: function (){
/// <Summary>
/// Builds the footer for the calendar
/// </Summary>
This. _ footer = $ common. createelementfromtemplate ({
Nodename: "Div ",
Properties: {ID: This. get_id () + "_ footer "},
Cssclasses: ["ajax _ calendar_footer"]
}, This. _ popupdiv );
VaR todaywrapper = $ common. createelementfromtemplate ({nodename: "Div"}, this. _ footer );
This. _ today = $ common. createelementfromtemplate ({
Nodename: "Div ",
Properties :{
ID: This. get_id () + "_ today ",
Mode: "today"
},
Events: This. _ cell $ delegates,
// Cssclasses: ["ajax _ calendar_footer", "ajax _ calendar_today"]
Cssclasses: ["ajax _ calendar_today"]
}, Todaywrapper );
VaR clearwrapper = $ common. createelementfromtemplate ({nodename: "Div"}, this. _ footer );
This. _ clearbutton = $ common. createelementfromtemplate ({
Nodename: "Div ",
Properties :{
ID: This. get_id () + "_ clearbutton ",
Mode: "clear"
},
Events: This. _ cell $ delegates,
Cssclasses: ["ajax _ calendar_clear"]
}, Clearwrapper );
},
Here I have specified a new CSS attribute Ajax _ calendar_clear, allowing you to define the style of this button at will. and bind its events to the unified _ cell $ delegates. Therefore, add a processor to the _ cell_onclick method:
Case "clear ":
This. get_targetelement (). value = "";
This. _ blur. Post (true );
This. raisedateselectionchanged ();
Break;
Here, the most important word "clear" is not displayed yet, so obviously the work is not completed yet: Then add the word "clear" in the _ javasmlayout method:
If (! This. _ clearbutton. firstchild ){
This. _ clearbutton. appendchild (document. createtextnode ("\ u6e05 \ u9664 "));
}
Here, I use the \ U method to represent Chinese characters, because if you write Chinese characters directly, it seems to be garbled at least in my environment, so it should be represented directly by Unicode code. in addition, I changed the display FORMAT OF THE today and the last display year and month. The default display method of the first month and the next year is really not in line with the Chinese people's habits. the two display formats are in the _ javasmlayout method.
Finally, in the dispose method, clear the Clear button:
If (this. _ clearbutton ){
$ Common. removehandlers (this. _ clearbutton, this. _ cell $ delegates );
This. _ clearbutton = NULL;
}
This is almost a success, except for the two lines shown at the bottom, which is ugly ......
The display of the two rows is obviously unacceptable. In this case, open the calendar.css and modify it.
Because you want to put the date and the clear button of today on the same line, first modify. Ajax _ calendar_today and. Ajax _ calendar_footer:
. Ajax _ calendar_footer {Height: 15px; width: 100%; text-align: Left ;}
. Ajax _ calendar_today {cursor: pointer; padding-top: 3px; float: Left ;}
Then add an Ajax _ calendar_clear class:
. Ajax _ calendar_clear
{
Font-weight: bold;
Color: blue;
Text-Decoration: underline;
Cursor: pointer;
Float: right;
Padding-top: 3px;
}
Now it's a success.