Enter key issue on service portal form

nagaraju8
Kilo Guru

Hi All,

I am facing one issue on service portal form. I have a single line text field on form, once I enter some text and pressing "enter  key" submitted the form automatically with out adding to cart. User preference "enter_submits_from " value already set to false. Please any one suggest me.

Any help would be much appreciated!!

Regards,

NJ

 

4 REPLIES 4

Allen Andreas
Administrator
Administrator

Try looking in your client script for "keypress" and change it out for this:

$scope.keyPress = function(event) {
if (evt.keyCode == 13 && !evt.shiftKey) {
    event.preventDefault();
if ($scope.data.journalEntry)
   $scope.postEntry($scope.data.journalEntry);
}
}

This will treat Enter normally, and not allowing it to send through. This is more so useful on the ticket conversations widget, but can apply elsewhere as well. It takes the process of pressing enter away from submitting and reverts it back to being like a normal enter.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi Allen,

My widget client script already having below script.

$scope.keyPress = function(event) {
if (event.keyCode === 13 && !event.shiftKey) {
event.preventDefault();
if ($scope.data.journalEntry)
$scope.postEntry($scope.data.journalEntry);
}
}

Do I need to do any change in above script?

Regards,

NJ

dpalmer
Kilo Guru

Not sure if you ever fixed this, but what worked for me was creating a function in the client script: 

 

$scope.isEnter=function(evt){
		var tagName = evt.target.tagName.toLowerCase();
		if(evt.keyCode==13&&tagName != 'textarea'){
			evt.preventDefault();
		}
	};

 

Then attach this function to the ng-keypress listener on the form:

<form ng-keypress="isEnter($event)"><!--ng-keypress="isEnter($event)"-->
            <div ng-class="{'wrapper-md': data.sc_cat_item._view.length}">
              <!-- display view and model -->
              <sp-model form-model="::data.sc_cat_item" mandatory="mandatory"></sp-model>
            </div>
            <div ng-if="data.sc_cat_item.sys_class_name != 'sc_cat_item_content'" class="button-wrapper">
              <label tabindex="0" ng-if="!submitted"><sp-attachment-button></sp-attachment-butto

 

Let me know if that helps.

And the reason why i single out the textarea tag name is so you can add new lines by pressing enter when your in the textarea, so we need the enter key to work as intended.