Set Value on dijit/form/FilteringSelect after its already been created - dojo

I have FilteringSelect using a MemoryStore. When a user types a value that is not in the store, they are prompted, asking if they would like to add the new value to the store.
If they do, we call the server, create the new item, and on the response, we publish an event.
The topic subscriber is notified that a new item was created and added to the MemoryStore, which adds the option to the filteringselect.
At this point, the filtering select still has the same displayValue, and the option exists in the select. FilteringSelect.get("value") still returns "".
If you were to type a space, then hit backspace, (ending up with the same value), FilteringSelect.get("value") would return the correct item id.
FilteringSelect.set("value", data[0].id) doesn't do anything, no exception thrown, no affect.
Here's the code, contains some of the random calls I tried.
require(["dojo/store/Memory", "dojo/_base/array", "dojo/topic"],
lang.hitch(this, function(Memory, array, topic) {
this.liftStore = new Memory({
data: []
});
array.forEach(data, lang.hitch(this, function(entry, i) {
this.liftStore.data.push({
name: entry.Name,
id: entry.ID,
identifier: entry.ID
});
}));
this.lift.set("store", this.liftStore);
topic.subscribe("LiftLog/NewLift", lang.hitch(this, function(data) {
debugger;
data[0].selected = true;
data[0].identifier = data[0].id;
this.liftStore.data.push(data[0]);
this.lift.reset();
this.lift.set("value", data[0].id);
this.lift.set("value", data[0].id.toString());
}));
}));

Have you tried setting the item (i.e. filteringSelect.set("item", newItem) instead of setting the value? Note that you should give it the whole item, not just the id or the displayed value.
So, push the item into the store, and then set the item on the FilteringSelect:
this.liftStore.data.push(newItem);
this.lift.set("item", newItem);

Related

Using AfterSubmit UserEventScript with SuiteScript 2.0

I'm pretty new to SuiteScript 2.0, so far it has been an insane learning experience.
Currently I am trying to write a script that will take a new Item Fulfillment record that is just being created, get the newly generated ID and place that value onto another record. I have been trying to test this by setting the value of a field on the same record with no luck. The script will run, but nothing sticks. The field I am setting the value of always remains blank.
/**
#NapiVersion 2.0
#NScriptType UserEventScript
*/
define(['N/record'],
function(record) {
function afterSubmit(scriptContext) {
if (scriptContext.type !== scriptContext.UserEventType.CREATE)
return;
var rec = scriptContext.newRecord;
rec.load({
type: record.type.ITEMFULFILLMENT,
id: rec
});
var itemFul = rec.getValue({
fieldId : 'tranid'
});
rec.setValue({
fieldId: 'custbody_mod_billoflading_ref',
value: itemFul
});
rec.save();
};
return{
afterSubmit: afterSubmit
};
});
What am I doing wrong? Again I am fairly new to SuiteScript 2.0 and learning a ton along the way! I appreciate any help I can get!
First of all, is your UserEvent deployment on an Item Fulfillment?
If YES, there's no need of loading the record again
However, you will need to load the 'other' record in which you need to set the value. Store the loaded record in a variable
var otherRecord = rec.load({
type: 'OTHER RECORD TYPE'
id: 'OTHER RECORD ID'
});
Also, you are trying to perform setValue on the current Record (i.e. rec)
You will need to do setValue on the record you loaded, following a record.save() to save it.
otherRecord.setValue({
fieldId: 'custbody_mod_billoflading_ref'
value: itemFul //your code variable
});
otherRecord.save();
ALTERNATIVELY,
You can use record.submitFields() API which would make your life much easier. Syntax is as below -
var id = record.submitFields({
type: record.Type.SALES_ORDER,
id: 1,
values: {
memo: 'ABC'
},
options: {
enableSourcing: false,
ignoreMandatoryFields : true
}
});

DataTables does not save state of date range search

I am using data tables to display a list of events of different types. Besides the default global text search I need to
1. filter list by event type
2. filter list by date range (show only today -> infinity)
3. Save the state of the table for the the current session.
The state saves as expected except for the date range search which is always reset. Am I missing something or custom search functions are out of the scope of state saving? Here's the relevant code in jQuery:
Fist I add my own search function through the provided method. This works except it's state is not saved
// Extend search()
var threshold_timestamp = xxxxxxxxxxxx // set for beginning of today)
$.fn.dataTable.ext.search.push(
function( settings, data, dataIndex) {
var timestamp = parseInt(data[1]); // event date timestamp
if (timestamp > threshold_timestamp) {
return true;
}
return false;
}
);
Then I add a listeners for the select used to switch between the event type options ('','Event','Sports','Dance'...) and the button user to turn on/off the date range filter
$('#filter-by-type').on('change', function() {
table.columns(0).search( $(this).val() ).draw();
});
$('#dt-history').on('click', function() {
// Logic to toggle threshold_timestamp between 0 or value
table.draw();
});
Then I call DataTables
var table = $('#example').DataTable( {
ajax: "datasource.json",
stateSave : true,
stateDuration: -1,
columns: [
{ data: "type"}, //str as 'Sport','Dance'
{ data: "date"} // int as 1528572000
]
});
I managed to scratch my head sideways and "save the date search" using localstorage but that is a hack. On page load I trigger a button click to execute the search so initially the tables seems empty, the "No data available in table" message appears and then the filtered results display. As a second hack I will suppress that message so when there will really be no data... there will be no message :(

Resetting to initial data in Vue

I've got some form data that I display using a readonly input that is styled to look like plain text. When users click an edit button, they can then edit the inputs and either save or cancel.
My issue is obviously that when a user clicks cancel, the data they entered into the input remains (even though it isn't saved to the DB). I'm trying to figure out a way to reset the input to its initial data. I'm aware of this answer, but it doesn't seem to work because the data is fetched on creation.
This fiddle is similar except for the fact that the data in the real app comes from an axios call. The equivalent call is essentially:
fetch() {
axios.get(this.endpoint)
.then(({data}) => {
this.name = data.data;
});
}
Annoyingly, the fiddle actually works. However in my actual implementation it doesn't. The only difference with the app is that the data is an array.
How can I make this work?
This fiddle represents what my code actually does.
In the code:
data: () => ({
endpoint: 'https://reqres.in/api/users',
users: [],
initialData: []
}),
//...
edit: function(index) {
this.users[index].disabled = false
this.initialData = this.users
},
reset: function(index) {
this.users[index].disabled = true
this.users = this.initialData
}
Since users and initialData are arrays, you must use index when you access them.
So, at first sight, the change would be from:
this.initialData = this.users
To
this.initialData[index] = this.users[index]
But this won't work. Since this.users[index] is an object, whenever you change it, it will change what this.initialData[index] holds, since they are both just pointing to the same object. Another problem is that when you set it like that, the initialData won't be reactive, so you must use Vue.set().
Another thing, since you just want to reset the first_name property (the one you use at <input v-model="user.first_name" >), you should then assign user[].first_name to initialData[index].
Considering those changes to edit(), in the reset() method, the addition of [index] and of the .first_name field are enough. Final code:
edit: function(index) {
this.users[index].disabled = false
Vue.set(this.initialData, index, this.users[index].first_name);
},
reset: function(index) {
this.users[index].disabled = true
this.users[index].first_name = this.initialData[index]
}
JSFiddle: https://jsfiddle.net/acdcjunior/z60etaqf/28/
Note: If you want to back up the whole user (not just first_name) you will have to clone it. An change the order of the disabled property:
edit: function(index) {
Vue.set(this.initialData, index, {...this.users[index]});
this.users[index].disabled = false
},
reset: function(index) {
Vue.set(this.users, index, this.initialData[index]);
}
JSFiddle here. In the example above the clone is created using the spread syntax.
Input is immediately updating the model. If you want to do something like edit and save you have to take a copy and edit that. I use lodash clone to copy objects then update the fields back when save is clicked. (of course sending message to server.)

PreliminaryEstimate's Value resets to old value on saving with new value

I am trying to edit and save the PreliminaryEstimate Value of a portfolio item through Estimation Board but it reset it back to the original value. I am using PreliminaryEstimateValue in the board but when the card is moved, i reset the PreliminaryEstimate to new column value.
var store = Ext.create('Rally.data.wsapi.Store', {
model: 'PreliminaryEstimate',
fetch: ['ObjectID','ObjectUUID','VersionId','Description','Name','Value','CreationDate','Subscription','Workspace','RevisionHistory'],
autoLoad: false,
limit: Infinity,
disableMetaChangeEvent: true
});
beforecarddroppedsave: function (scope, card, type, sourceColumn, eOpts) {
card.record.data.PreliminaryEstimate = _.omit(_.filter(this.preliminaryEstimateStore.getRange(), function (pe) { return pe.data.Value === card.record.data.PreliminaryEstimateValue })[0]
.data, ['Summary', 'creatable', 'deletable', 'updatable', '_CreatedAt', '_objectVersion', '_uuidRef']);
the options also has the new value. It saves succesfully but the old value does not change to new
handleBeforeCardDroppedSave: function (options) {
options.record.save({})
Thanks!
If you inspect the network traffic is it actually sending that value over the wire? I'd try using the setter method rather than directly manipulating the data object. My guess is that the record does not think it has any changes to save with the way your current code is written.
card.record.set('PreliminaryEstimate', '/preliminaryestimatevalue/12345');

Dojo: Select of empty value for FilteringSelect while required=false

Please look on this code:
dojo.require('dijit.form.FilteringSelect');
dojo.require('dojo.store.JsonRest');
dojo.declare('JsonFilteringSelect', dijit.form.FilteringSelect, {
constructor: function (options) {
dojo.declare.safeMixin(this, options);
if (this.url) {
this.store = new dojo.store.JsonRest({
target: this.url
});
} else {
console.log('JsonFilteringSelect: options.url is not defined');
}
}
});
var getPersonJsonFilteringSelect = new JsonFilteringSelect({
url: '/person/get',
name: 'Test',
title: 'Test title',
required: false,
autoComplete:false,
value: '',
pageSize:10,
queryExpr:'${0}'
}, dojo.byId('select'));
getPersonJsonFilteringSelect.startup();
});
Use case: Suppose I have 20 results into my FilteringSelect.
User selects 1 value of FilteringSelect.
This value set as value of
FilteringSelect.
But after user decides to change this value on
empty value.
As I understand, because required:false FilteringSelect should allow
to set empty value, but it is not. I observe this behavior here:
User clicks FilteringSelect textbox
User clears it
While user presses "Tab" or clicks by other element - FilteringSelect automatically selects first value.
How could I allow user to set empty value into FilteringSelect?
You should add an empty entry ("" or null maybe? I know "" works) to your data store after it's loaded (I'd put it at the beginning) but before startup of the widget.
The "required" issue is strange with FilteringSelect because it won't let you select any arbitrary value -- it has to be an entry from the data store. Yet, if it's not required shouldn't it not care?... Dojo is strange sometimes.