Anurag-Sharma
Anurag-Sharma

Reputation: 4408

web2py start date and end date conflicts

Suppose in a web2py application I have to two date field like - start date and end date . And I also have a form to enter dates . So when the user enters the start date then the end dates should not be not previous from start date and also they should not be highlighted in the select calendar . How would I do that ?

Upvotes: 1

Views: 228

Answers (1)

Richard
Richard

Reputation: 771

Anthony is rigth, though you can create a custom validator that can do the check you want. It is not easy to do, but it is feasible.

You can try this :

db.table.start_date = IS_DATE(format=T('%Y-%m-%d'))
db.table.end_date = IS_DATE_IN_RANGE(format=T('%Y-%m-%d'),
        minimum=form.vars.start_date if form.vars.start_date else None,
        maximum=None,
        error_message='must be later then %s' form.vars.start_date.strftime('%Y-%m-%d') if form.vars.start_date else 'start_date should be precised')

I have not tested.

For the datepicker part of your question, I have no workaround... Sorry!

Hope it helps

Richard

Upvotes: 1

Related Questions