Prestashop 1.7.8 form fields validation - validation

How to add custom class for example "error" to requiered fields when customer forget to fill them?
For example in registration form. When customer forget to fill multiple fields and click on Submit how to highlight all that missing fields?

Not a pretty solution, but it works
$('#login-form').submit(function() {
var $inputs = $('#login-form :input');
let hasError = false;
$inputs.each(function() {
if(!$(this).val() && $(this).prop('required')){
$(this).addClass('required-error-class');
hasError = true;
}
});
if(hasError){
return false;
}else {
return true;
};
});
A nicer solution is to use e.preventDefault and ajax

Related

Create New Form not reload after save

working good in crm 2011 but not in crm 2013 online
On opportunity Entity create New record form i show only:
1.Some attributes(all other fields/Section/Tabs are hide on form)
2.and an Html button like
function OnFormLoad(){
if(Xrm.Page.ui.getFormType() == 1 ) {
SetRequiredLevelToNone();
createHtmlButton("Save");
HideTabsAndSections()
}
else {
}
}
On click of Html button following function is triggered.
function showWholeForm() {
Xrm.Page.data.entity.save();
}
I want to show all the fields of form after save, means want to reload whole form.
As working in crm 2011
The save method in CRM 2013 will not refresh the page anymore. The new refresh method should be used in this case, as follows:
Xrm.Page.data.refresh(save).then(successCallback, errorCallback);
save: Boolean value to be passed as true if data should be saved
after it is refreshed.
successCallback: Function to call when the operation succeeds
errorCallbak: Function to call when the operation fails, that will be passed an object with 2 properties - error code (number) and localized error message (string)
You could find the method documented here: http://msdn.microsoft.com/en-us/library/dn481607(v=crm.6).aspx
I think you should first disable the auto-save if you want consistency with CRM 2011.
function OnSaveDisableAutoSave(eventArgs) {
var saveType = eventArgs.getEventArgs().getSaveMode();
if (saveType == 70 ||saveType == 2)
{ //Disable AutoSave
eventArgs.preventDefault();
}
}
and then
function showWholeForm() {
Xrm.Page.data.refresh(true).then(successCallback, errorCallback);
}
To fix this you can do:
var saved = false;
function onLoad(){
checkIfFormShouldBeReadOnly();
attachEvent();
}
function attachEvent() {
Xrm.Page.data.entity.addOnSave(executeOnSave);
}
function executeOnSave(saveExecution) {
if (!saved) {
saved = true;
Xrm.Page.data.save().then(
function () {
checkIfFormShouldBeReadOnly();
},
function (errorCode, message) {
Xrm.Page.data.refresh();
}
);
}
}

(Magento) How to set freeshipping in shopping cart when none is selected?

I tried using the event "controller_predispatch_checkout_cart_index" and used this function. Only to mention after i login, and go direct to page/checkout/cart, it does not work, but after reloading the page it does work... Whats happening???
const FREE_CODE = 'freeshipping_freeshipping';
public function predispatchCart($observer)
{
$quote = Mage::getSingleton('checkout/cart')->getQuote();
if(! $quote->getShippingAddress()->getShippingMethod())
{
$quote->getShippingAddress()
->setShippingMethod(self::FREE_CODE);
//->save();
return true;
}
}
}

Custom component check-in/check-out best practices

I'm creating a component in Joomla! 1.7 and I'd like to take advantage of the framework's check-out/check-in features. Currently
How do I mark a component record as "checked out" when a user requests the edit task for that record?
How do I mark a record as "checked in" when the user attempts to store his or her edits?
How do I test the checked-in/checked-out status of a component's record at edit time?
Thanks!
Basicly you need two methods in your model, which you can call whenever you want to:
function checkin()
{
if ($this->_id)
{
$item= & $this->getTable();
if(! $item->checkin($this->_id)) {
$this->setError($this->_db->getErrorMsg());
return false;
}
}
return false;
}
function checkout($uid = null)
{
if ($this->_id)
{
// Make sure we have a user id to checkout the article with
if (is_null($uid)) {
$user =& JFactory::getUser();
$uid = $user->get('id');
}
// Lets get to it and checkout the thing...
$item= & $this->getTable();
if(!$item->checkout($uid, $this->_id)) {
$this->setError($this->_db->getErrorMsg());
return false;
}
return true;
}
return false;
}
To mark item as checked, first of all you have to have column called checked_out with default value 0, also you need checked_out_time to store time, when item was checked out.
Hope it helps.

Show graphic next to a textbox if it failed validation

I have a simple MVC form: First name, Email Address which are both required. If the user hits the submit button I would like to display a graphic next to the textboxes that failed validation.
I am using Data Annotations and Validation summary already.
Thank you!
I would try something like this:
//ViewModelClass
public class yourViewModel
{
//...
bool showPictureName {get;set;}
}
//controller
{
//...
var NameErrors = ModelState["yourViewModel.Name"].Errors;
if(!Modelstate.IsValid)
{
// put your code here
if(NameErrors.Count() != 0)
yourViewModelObject.showPictureName = true;
}
}
//View
#{ if(Model.showPictureName == true)
<img .../>
}

Calling validate function on button and getting the result (true/false)

I am trying to do following task:
$("#btn1").click(function(){
var success = $("#myFrm").validate();
if (success == true) {
// post form through ajax
}
else{
// set focus on first field
}
});
I think you're looking for the valid() method:
$("#btn1").click(function(){
var success = $("#myFrm").valid();
if (success == true) {
// post form through ajax
}
else{
// set focus on first field
}
});
This assumes, of course, that you've configured jQuery validate on the form in question (using $("#myFrm").validate()).

Resources