Remember the last entry value entered
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 08:23 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2023 10:44 AM
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 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2023 05:57 PM
<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);
});