I the osclass When I post listing, choosing a city is not required. How can I make it required ? When I select city, it shows in the post, but I also can post listing without selection the city, but I want the city to be required.
Asked
Active
Viewed 490 times
1 Answers
0
You have two ways to do it:
1- Hook method
Using the pre_item_post (osclass < 3.3) or pre_item_add (osclass >=3.4).
osc_add_hook("pre_item_add", function($aItem) {
if($aItem["city"] !== "") {
osc_add_flash_error_message(_e("Please select a city", "your_theme"));
$this->redirectTo(osc_item_post_url());
}
});
2- Javascript method
Using jQuery Validate, like in Bender theme.
$('.form-horizontal').validate({
rules: {
region: {
required: true
},
city: {
required: true
}
},
messages: {
region: {
required: "Please select a region"
},
city: {
required: "Please select a city"
}
}
});

Hussard
- 656
- 7
- 14