Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Clearing input field value and getting back the same

Srinivas_S
Tera Contributor

Hi Everyone!

 

I have a requirement to clear an input field value using a button and get the same value with the click of another button.

Basically, I have one Input field and two buttons(click1 and click2).

When I click the click1 button, the value is getting cleared but when I click the click2 button, it is showing true instead of the value, could anyone please guide me?

c.click = function(){
        c.filterName = '';
    }
    
    
    c.clicks = function(){
        c.filterName = !'';
    }
<input  ng-model="c.filterName"  >

<button ng-click = "c.click()">Click 1</button>

<button ng-click = "c.clicks()">Click 2</button>

I have tried the above code, it is working but I want the exact value and not the boolean value.

 

Thanks

Srinivas

4 REPLIES 4

SudhirG
Kilo Sage

Hi @Srinivas_S ,

c.click = function(){
        c.currentVal = c.filterName;
        c.filterName = '';
    }
    c.clicks = function(){
        c.filterName = c.currentVal;
    }

Try this code.

 

Thanks

Hi @SudhirG, thanks for the update!

 

The above code is working only when we click the first button click and then the second button clicks.

If I click the second button first by name clicks and then the first button by name click, it again clears the value and shows boolean value.

It is working only when I click first button and then the second button.

Could you please guide me with this issue?

 

Thanks

Srinivas

Rahul Mane2
Kilo Guru

Try this one

 

c.click = function() {

c.filterName = '';

}

c.clicks = function() {

alert("Input value: " + c.filterName);

}

Hi @Rahul Mane2, thanks for the update, but I wanted to update on the input field only so I cannot try with an alert message. I have given HTML as well.

 

Thanks

Srinivas