Remember the last entry value entered

asher14
Tera Contributor

I have a requirement that "remember" the last entry the user typed for color field, and when they click "new" to create a new form that field populated with that last value entered until they change it. How can I do that ?

 

HTML: 

<div class="col-md-6">
<div class="form-group">
<label for="color">Color</label>
<input id="color" name="color" type="text" class="form-control" rows="1" ng-model="c.dataForm.color" placeholder="Color..." maxlength="40" >
</div>
</div>

 

CLIENT SCRIPT:

I need help with the client script to save that previous value the user entered on the ui form.

2 REPLIES 2

Sohithanjan G
Kilo Sage
Kilo Sage

Hi @asher14 , 

 

After entering any color value, you create a record in sys_user_preference table with some name & then when you create a new record, you can create that as default value like this

ng-model="c.data.color" ng-init="c.data.color = 'InitialValue'"


Please mark as Accepted Solution or helpful if you got it 🙂

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

Harish Bainsla
Tera Sage
Tera Sage

<div class="col-md-6">
<div class="form-group">
<label for="color">Color</label>
<input id="color" name="color" type="text" class="form-control" rows="1" ng-model="c.dataForm.color" placeholder="Color..." maxlength="40">
</div>
</div>

 

client script


var colorInput = document.getElementById('color');
var lastColor = localStorage.getItem('lastColor');
if (lastColor) {
colorInput.value = lastColor;
}

colorInput.addEventListener('input', function() {
localStorage.setItem('lastColor', colorInput.value);
});