After so much investigation I found one solution. I have tried for Offline shipping methods as described follows and its working fine for me:
Namespace/Module/view/frontend/requirejs-config.js
var config = {
"map": {
"*": {
"Magento_OfflineShipping/js/model/shipping-rates-validation-rules/flatrate": "Namespace_Module/js/model/shipping-rates-validation-rules/flatrate",
"Magento_OfflineShipping/js/model/shipping-rates-validation-rules/freeshipping": "Namespace_Module/js/model/shipping-rates-validation-rules/freeshipping",
"Magento_OfflineShipping/js/model/shipping-rates-validation-rules/tablerate": "Namespace_Module/js/model/shipping-rates-validation-rules/tablerate"
}
}
};
Namespace/Module/view/frontend/web/js/model/shipping-rates-validation-rules/flatrate.js
define([], function () {
'use strict';
return {
/**
* @return {Object}
*/
getRules: function () {
return {
'country_id': {
'required': true
},
'city': {
'required': true
},
'telephone': {
'required': true
}
};
}
};
});
Namespace/Module/view/frontend/web/js/model/shipping-rates-validation-rules/freeshipping.js
define([], function () {
'use strict';
return {
/**
* @return {Object}
*/
getRules: function () {
return {
'country_id': {
'required': true
},
'city': {
'required': true
},
'telephone': {
'required': true
}
};
}
};
});
Namespace/Module/view/frontend/web/js/model/shipping-rates-validation-rules/tablerate.js
define([], function () {
'use strict';
return {
/**
* @return {Object}
*/
getRules: function () {
return {
'postcode': {
'required': true
},
'country_id': {
'required': true
},
'region_id': {
'required': true
},
'region_id_input': {
'required': true
},
'city': {
'required': true
},
'telephone': {
'required': true
}
};
}
};
});
These rules will automatically applied on change event of telephone and city fields.
Note: I have tried for Offline shipping methods only. If you wan
to do it for other shipping methods, then you can try in the same way.
Best Answer
I fix that editing this function on
shipping.js
:and declarate var: