Trying to convert a custom form module to the new ...
# suitecommerce
c
Trying to convert a custom form module to the new Extensibility API. I am getting the following error when submitting. https://developers.suitecommerce.com/develop-your-first-extension.html
Copy code
CustomFormView.prototype.saveForm = function (e) {
		
		e.preventDefault();

		var promise = CustomFormView.prototype.saveForm.call(this, e);

		if (promise) {
			promise
			.fail((jqXhr) => {
				// Do something with the error code.
				jqXhr.preventDefault = true;
				const errorCode =
					jqXhr &&
					jqXhr.responseJSON &&
					jqXhr.responseJSON.errorCode && jqXhr.responseJSON.errorCode;
				})
			.done(() => {
				console.log('done');
				// Do something when the formModel is saved successfully.
			})
			.always(() => {
				console.log('always');
				// Do something always.
			});
		}
		return promise;
	}
Error
Copy code
shopping_1.js?t=1612980274111:4782 Uncaught TypeError: this.formModel.validate is not a function
    at a.getFormFieldValue (shopping_1.js?t=1612980274111:4782)
    at a.s.onFormFieldChange (shopping.js?t=1612980274111:1)
    at HTMLDivElement.dispatch (shopping.js?t=1612980274111:1)
    at HTMLDivElement.f.handle (shopping.js?t=1612980274111:1)
    at Object.trigger (shopping.js?t=1612980274111:1)
    at Object.simulate (shopping.js?t=1612980274111:1)
    at HTMLDocument.r (shopping.js?t=1612980274111:1)
s
It's hard to say with this information but the problem is probably within your form view. You're probably either not setting the object's prototype so that it has
validate()
, or you haven't included a
getFormValues
function
c
yes.. part 4
I do have getFormValues added
My plan is to use the same backend service to submit the data as we don’t have the time to update to SS2.0 right now.
s
OK. and do you notice anything significantly different between what I have in my file and yours?
SS1.0 should be fine
c
I am not using
Copy code
this.formModel.on('sync', function () {
            Backbone.history.navigate('preferences', {trigger: true});
        });
s
That's ok
c
My save form looks like
Copy code
CustomFormView.prototype.saveForm = function (e) {
		e.preventDefault();
		var promise = CustomFormView.prototype.saveForm.call(this, e);
		if (promise) {
			promise
			.fail((jqXhr) => {
				// Do something with the error code.
				jqXhr.preventDefault = true;
				const errorCode =
					jqXhr &&
					jqXhr.responseJSON &&
					jqXhr.responseJSON.errorCode && jqXhr.responseJSON.errorCode;
				})
			.done(() => {
				console.log('done');
				// Do something when the formModel is saved successfully.
			})
			.always(() => {
				console.log('always');
				// Do something always.
			});
		}
		return promise;
	}
s
OK. And on your model, you've not added any validation rules or anything right? It's just the standard model with a url root and the prototype?
c
Yes
In your example, is line 42 correct?
Copy code
var promise = SCFormView.prototype.saveForm.call(this, e);
s
oh I've just noticed
You're calling your own saveForm method within that method
Copy code
CustomFormView.prototype.saveForm = function (e) {
		e.preventDefault();
		var promise = CustomFormView.prototype.saveForm.call(this, e);
Call the parent class, like my code sample
c
will update
I had ‘this.model’ and not ‘options.model’.
Copy code
function ExampleUserPreferencesFormView (options) {
        SCFormView.call(this, options.model);

        this.formModel.on('sync', function () {
            Backbone.history.navigate('preferences', {trigger: true});
        });

        this.template = example_userpreferences_form_tpl;
    }
In ‘JavaScript/Example.UserPreferences.Model.js’ why is “true” added after getExtensionAssetsPath()? Does this trigger a ss2 path?
Copy code
function ExampleUserPreferencesModel () {
        SCModel.call(this);
 
        this.urlRoot = function urlRoot () {
            return Utils.getAbsoluteUrl(
                getExtensionAssetsPath(
                    "Modules/UserPreferences/SuiteScript2/Example.UserPreferences.Service.ss"
                ), true
            )
        }
    }
s
Does this trigger a ss2 path?
Yes