Enable/Disable Submit button in SP by option

Ricky S Larsson
Tera Guru

I want to make it available for users to enable/disable the Submit button for each Catalog Item in the SP from the Catalog Item view.

Just like how the Add To Cart button in the SP widget can be enabled/disabled by the No Cart option:

find_real_file.png

find_real_file.png

 

What I managed to understand is that the Add To Cart button is controlled by an ng-if statement

HTML Template:

<button ng-if="c.showAddCartBtn()" name="submit" ng-disabled="submitted" ng-click="triggerAddToCart()" class="btn btn-default">${Add to Cart}</button>

Client Script:

c.showAddCartBtn = function() {
		return c.options.show_add_cart_button &&
			c.data.sc_cat_item.sys_class_name !== "sc_cat_item_producer" &&
			!c.data.sc_cat_item.no_cart;
	};

 

I tried to create my own ng-if statement like c.showSubmitBtn() and a function, but I can't make it work. What would be required to get the same functionality as the No Cart checkbox option but for the Submit button instead?

1 ACCEPTED SOLUTION

I was able to solve it by basically just copying the code for the Order Now functionality:

HTML Template:

<button ng-if="c.showSubmitBtn()" name="submit" ng-disabled="submitted" ng-click="triggerOnSubmit()" class="btn btn-primary">{{submitButtonMsg}}</button>

Client Script

c.showSubmitBtn = function() {
		return c.data.sc_cat_item.sys_class_name !== "sc_cat_item_producer" &&
			!c.data.sc_cat_item.no_order_now;
	};

So now I can enable/disable the submit button by checking/unchecking the No Order Now checkbox in the catalog item view.

View solution in original post

4 REPLIES 4

Simon Christens
Kilo Sage

Hi

You can try with ng-disabled

ng-disabled="submitted || (data.required_attachment && !attachments.length)"

This is used to disable the button depending if a checkbox on the catalog item "attachment required" is true or false.

I think that ng-if either shows or hides the button

I have not been able to test it yet, but I think ng-disabled would work. I will try it when I get the chance. Thanks!

I was able to solve it by basically just copying the code for the Order Now functionality:

HTML Template:

<button ng-if="c.showSubmitBtn()" name="submit" ng-disabled="submitted" ng-click="triggerOnSubmit()" class="btn btn-primary">{{submitButtonMsg}}</button>

Client Script

c.showSubmitBtn = function() {
		return c.data.sc_cat_item.sys_class_name !== "sc_cat_item_producer" &&
			!c.data.sc_cat_item.no_order_now;
	};

So now I can enable/disable the submit button by checking/unchecking the No Order Now checkbox in the catalog item view.

I removed the following syntax from the client script

c.data.sc_cat_item.sys_class_name !== "sc_cat_item_producer"

so that the Submit button would still show in Record Producers (otherwise they would have no buttons)