I have an odd necessity at my current project. I am using Semantic-Ui as a front-end framework.
One of my views includes semantic-ui dropdown component and this component gets it's datas from remote source. What I need is to call remote source manually. When I start texting, dropdown component calls to remote api and get datas back nicely, but I failed at triggering calls manually.
My question is, how can i call remote content at dropdown's onchange event.
My current code is (#searchInput is id of my input):
onChange: function (val) {
$('#searchInput').trigger('change');
}
Thanks for your helps and kind
Related
I am making an Angular 12 application, and I need change ngModel value via global/window method. (Because Android Webview can call from kotlin only public javascripts methods)
I'm tried use bind, and angular service. Method is called correctly, but ngModel not changed - input not filled.
Via bind, see on Stackblitz, or via service, see on Stackblitz too.
Unfortunately, the input is not filled in in any case. You can try on Stackblitz, via browser console.
So I need to update the ngModel value, but how?
You can fire a custom event as mentioned in this answer
I've updated your code to use custom event here StackBlitz
From console tab,
window.dispatchEvent(new Event('custom-event'));
I'm working on an Angular2 project (Resource Management) which requires data from the database (mongoDB) in real time. The basic function of the application is to drag a resource from bench and drop it to a project. After which a button is clicked which saves these values to the database. The problem is once the database is hit with the values, the same is not showing up unless the page is refreshed. Is there a way where we can pull data from the database without manually refreshing the entire page or pulling the data from DB at regular intervals so that the services have the latest data. I'm attaching my code here: Resource Management (drag n drop)
Thank you!!
If you want to get the data periodically.You can use timer.
ngOnInit() {
this.timer = Observable.timer(2000,5000);
// subscribing to a observable returns a subscription object
this.sub = this.timer.subscribe(t => this.geData(t));
}
geData(t) {
console.log(t)
}
You Could use socket.io for real time update with angular2 and mongodb
Is there a possibility to access and set the state and props of an existing React component through the browser (from inside another script or through console)?
I know there is a way with Angular to access the scope and change variables, but with React I haven't been able to find a way.
I would assume there must be some way because the React Developer Tools extension from Facebook is able to get all the information (Props, State, Component, Event Listeners) from the React components on the page, with the possibility to change them.
If there is a possibility to do this through JavaScript, which would be the way to do it?
If you have the React devtools extension, you can access the React scope via your browser console with $r.
First, select the component you wanna act on in the React devtools tab:
Then, use $r to act on the component, for example read state with $r.state or set state with $r.setState({ ... }) :
To set a react components's state from the browser, you can bind a function to the window object that will trigger the set state.
In the react component's constructor, you can do this.
constructor (props){
super(props);
window.changeComponentState = (stateObject) => {
this.setState ({stateObject});
}
}
In the browser console you can do this.
window.changeComponentState ({a:'a'});
WARNING: This is anti-pattern. This will work, but you should never never do this.
To set the state from your browser, stick this somewhere in your component, like in render():
globalSetState = function(state){this.setState(state)}.bind(this);
Note: It's important to leave off the var, as this is what makes the defined function globally accessible.
You can now call globalSetState({x: 'y'}) in your console.
Warning: This is mad ugly, and, like console.log() for debugging, should be deleted in your live app.
When back home is pressed app exists but it is not terminated yet.
When user press primary or secondary tile app is relauched.
Default way is to let application navigate to the last visited page in the navigation history.
I don't know if there is a bug but this way doesn't work as expected because any code inside page ready function executes but it doesn't count later when page is rendered. Static binding works but not dynamic.
I need to know what is the proper way of handling relaunch in an app that uses default navigation template?
What to do if I want clean start, destroy everything and than navigate to home?
How to overcome problem with framework not taking into consideration code inside page ready function?
Upon app initialization you should check for the ApplicationExecutionState, and do whatever you want in either case.
Thanks for your answer but it is quite clear from the start how to obtain ApplicationExecutionState.
Actually what I need was to execute all bindings and other post processing after DOM has been loaded in a promise timeout.
if (app.sessionState.previousExecutionState === 1) {
WinJS.Promise.timeout().then(function () {
performeAfterProcessing();
});
}
else {
performeAfterProcessing();
}
So if everyone encounters some strange behavior after application has been relaunched try to execute your code using promise timeout.
I am working on OnPublished event handler that will update one custom field of a project based on change in another field.
I am getting an error
Event Handler for event \ProjectPublished\ of type \PS.UpdateProjectStatusChangeDate.EventHandlerUpdateField\ threw an exception: ProjectServerError(s) LastError=CICOCheckedOutToOtherUser Instructions: Pass this into PSClientError constructor to access all error information
This is the code
//loading project data from server
//Every change on this dataset will be updated on the server!
ProjectDataSet projectDs = projectClient.ReadProject(projectId, projectSvc.DataStoreEnum.WorkingStore);
foreach (projectSvc.ProjectDataSet.ProjectRow row in projectDs.Project)
{
if (row.PROJ_SESSION_UID != null)
{
sessionId = row.PROJ_SESSION_UID;
break;
}
}
//send the dataset to the server to update the database
bool validateOnly = false;
Guid jobId = Guid.NewGuid();
projectClient.QueueUpdateProject(jobId, sessionId, projectDs, validateOnly);
Unlike other answers where we are running the code when the project is in checked-in state, we are checking-out and assigning new SessionID.
But when the event handler fires, the project is already is checked-out. So how do I get the SessionID. I think that is where the code is breaking.
Logically that makes sense. While project is checked out that means that somebody can change it at any time and in any way.
So even if your idea works your update can be overwritten by the next save done from Project Pro. Because Project Pro knows nothing about your manipulations.
I don't know anything about your system so let me guess that your users work with Project Pro mostly. In this case you can add your event handler to Application.ProjectBeforePublish msdn link event and update the field from Project Pro. But please keep in mind that your users will be asked to save the project before publishing.
If the solution with Project Pro does not work for you - you can flag published projects somehow and as soon as the project is checked in - do check out, update the field, save and publish the project again.