ASP.NET MVC Calendar Design - asp.net-mvc

I want to design a calendar in asp.net mvc and I want to take month information as a string in address bar. What should I do? And after that I have to show this month from index.aspx. How can I do this?

It's a little unclear what you're trying to do. If you're trying to present a calendar so that a user can input a date, I'd use jQueryUI's datepicker. The default style looks pretty nice, it's simple to use, and it works really well.
After re-reading your question, it seems you want your URL to be in some sort of date format. If this is the case, you need a custom route, like the one in this article. After you have created your custom route, printing the date is rather simple: pass the month part of the date from your controller down to your view and display it.

Related

Capybara DayPickerInput selection?

Has anyone had any luck in figuring out how to use the react library https://react-day-picker.js.org/docs/input/
With Capybara/Selenium? Unfortunately it doesn't allow simply typing in the text such as MM/DD/YYYY like most date-pickers. This only allows mouse selection.
Or is specifically setting the value basically the only way to do so?
Without an example which shows the actual configuration of react-day-picker you're dealing with it's impossible to say exactly what you need to do, but the general rule is if you are testing the sites functionality then do what a user would need to do. In your case that may mean click on the forward/back month arrows until you get to the desired month, then click on the specific day element. Assuming the date you want to select is in the future (September 20, 2019) it would be something like
caption = find('.DayPicker-Caption')
until caption.has_text?('September 2019', wait: 0) do
current_month = caption.text
find('.DayPicker-NavButton--next').click
# wait for month to change
expect(caption).not_to have_text(current_month)
end
find('.DayPicker-Day', exact_text: '20').click
If you're not actually testing functionality (web scraping, etc) then you can use execute_script to call the react-day-picker JS API and set a specific date.

zf2 validator - valid only if date is a weekday

Using ZF2 \Zend\Validate, is it possible to validate a date only if it is a weekday? So weekends, regardless of month or year, will fail the validation?
The input is a normal text field.
I don't think that Zend\Validate has already a validator to check that.
You'll probably need to write your own custom validator to do your check.
Have a look at this answer to see how to perform the actual check (actually that answer check the converse, but it'll be easy to adapt it)

Grails Timepicker

I need to save Date Time in the (oracle) database in one column, which is sqlType of timestamp (looks like 01-JAN-14 12.00.00.000000 AM). While learning grails I've been using the Joda lib with it's "time picker".
The Joda timepicker has worked well, but now that I'm looking to go primetime I'm looking for something a little more user friendly. Frankly, text boxes might be more user friendly than the drops downs joda gives you.
Anyway, I'd like to remove joda and use something like this:
http://trentrichardson.com/examples/timepicker/
but I can't figure out how to implement it in grails. In my view, if I put:
<input type="text" name="endDate" id="endDate" value="${exampleInstance?.endDate}" />
in place of the g:datePicker, it works fine (the picker that is), except nothing gets saved to the database, and no errors are generated. I hit Save and the Show view comes up with an empty endDate field. Do I need more input tags?
Is there some easy way to implement a modern looking date+time picker that I've missed?
Furthermore, I see there is a plugin for this picker here
http://grails.org/plugin/jquery-ui-timepicker
But being that there isn't any documentation, I'm not sure how to use that either (?)
ANSWER
in controller save/update put something like:
def endDate = params.date('endDate', 'yy-MM-dd h:mm')
//println "Date from Picker was "+endDate
params.endDate = endDate
No further casting was necessary being that it ended up I could format the datepicker control to a very close format as what's in the database, but had I needed to cast from one odd format, or a string, to another, I toyed with this code, which is more psuedo than anything as I was thinking through the process (I'm sure there's a totally Groovy way to do this same thing):
SimpleDateFormat inputFormat = new SimpleDateFormat("yy-MM-dd HH:mm:ss.S");
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yy h.mm.ss.S a");
def v = params.endDate
Date date = inputFormat.parse(v);
String temp = sdf.format(date)
Date dateOut = sdf.parse(temp)
println dateOut
The datepicker, is your UI component therefore, you can have any library that you wish for UI and anything else for back-end. Mostly they are easy to implement, if they provide a little bit of documentation!!.
The timepicker for jQuery ui plugin, that you provided the link, is exposing a resource called jqueryUiTimePicker which depends on jQuery and jQuery-ui. So simply by including this resource into you resources configuration you should be able to utilize it. Its no different than defining your own resource and use it.
About saving issue that you have, on your save pass parameter failOnError:true so you can see the errors if any.
I have created a sample project that utilizes this plugin hope it helps
In your controller, you will need to parse the parameter value to a Date value. Something like,
def endDate = params.date('endDate', 'dd-MM-yyyy')
dd-MM-yyyy is whatever format the jquery plugin submits the date value. (println params for this or look up the plugin documentation)
If you want a date format binding to happen automatically, check the Date Formats For Data Binding in the doc http://grails.org/doc/latest/guide/single.html#dataBinding for a way to globally specify the format

Handling different date formats in ROR

I am trying to build a ROR app that allows users to enter date in various formats such as 12/31/11 (month/day/year) or 31/12/11 (day/month/year). In order to interpret date format, I will have a select field from where user can select the format of date. I can use Date.strptime(value, format).to_s() in controller before saving record.
However, I am not sure is controller right place to put this information. Is there a way I can push this to model..say in before save method.
You could just save the data as it is (in the controller), and have another field in the model telling it how to interpret the data. Then, in a before_validation callback, you could try parsing the date according to the given format and writing it to the same field, now as a date. Problems may arise on the way back. Then, to display it in the view again, you could write helpers - but better yet, provide a method in the model (for instance, formatted_date) that will compute and display the date.
However, this requirement sounds strange. Why is the user's responsibility to select a date format? Shouldn't it be based on the user locale?
In any case, I suggest you register your date formats in an initializer, rather than repeting the format strings throughout the application.

Is there a simple-to-implement datepicker for Symfony?

I'm working on a site in Symfony that displays graphs of a range of metrics.
Currently I'm trying to implement a simple datepicker to decide what graph to show.
Preferably in one of these forms:
a simple calendar icon that presents a calendar when clicked
three drop-downs for the day, month and year
The latter only as a plan-b really, the first would be great.
Now, I'm new to Symfony and I'm quite spoiled. Everything I wanted so far has always been but a plugin/helper/tag away. I sort of hoped that it was the same for a date-picker like this one, but so far I'm coming up empty. There are a few possibilities, but they all require a crap-load of dependencies and seem to have a low success-rate with people who have tried to implement them.
I have the feeling that I'm overlooking something that's right in front of me.
So in short: what is, according to you guys, the simplest way to implement such a date picker in Symfony? And if you have one, do you have a link with a clean and clear explanation?
Thanks a bunch,
Dieter
I use sfWidgetFormJQueryDate widgets based on jquery-ui from sfFormExtraPlugin.
class YourFormFilter extends BaseYourFormFilter
{
public function configure()
{
$date_widget = new sfWidgetFormJQueryDate(array(
'date_widget' => new sfWidgetFormDate(array('format' => '%day%/%month%/%year%')),
'culture' => 'ru'
));
}
}
Check this one, it is intended for Syfmony2
http://blog.azancadas.com/2011/07/symfony2-datepicker/

Resources