How to select a radio button by default in formly form angularjs - angular-formly

How do I set "onDemand" as default when the form is loaded?
(Background: There is a hidden text box which should only be visible when "Predefine" is checked. Unfortunately, it is visible when the form gets loaded first. At this point I thought about making the onDemand checked by default to keep the textbox invisbile at first page load)
{"key":"discountType","type":"radioType", "templateOptions":{"options": [{"name":"OnDemand","value":"OnDemand"},{"name":"Predefined","value":"Predefine"}]}},
{"key":"discValue","type":"input","templateOptions": {"type":"input"}, hideExpression: "model.discountType=='OnDemand'"}
]
}

Did some trial and error after sleeping over it and I got it.
discount.discountInfo.discType="OnDemand"; resolved it.
var discount = this;
discount.title = title;
discount.discountInfo = {};
discount.fields=[{"key":"discountType","type":"radioType", "templateOptions":{"options": [{"name":"OnDemand","value":"OnDemand"},{"name":"Predefined","value":"Predefine"}]}},
{"key":"discValue","type":"input","templateOptions": {"type":"input"}, hideExpression: "model.discountType=='OnDemand'"}
]
discount.discountInfo.discType="OnDemand";

Related

How can you control visibility of datasource in Cesiumjs?

I want to display multiple datasources in a cesiumjs viewer but need to allow the user to select which ones they want to see at any given time. For example, if I load a kml and a czml file, how do I hide one and show the other? I can't find the cesiumjs way to do this with its API.
Update Feb 2016: A show flag has been proposed and may be added to a future version of Cesium.
Original answer:
Currently there is no show flag on the dataSource, however it is easy to add and remove the dataSource from the list of available dataSources, and this is used to get the show/hide functionality.
Here's a working demo: Load the Cesium Sandcastle Hello World example, and paste the following code into the left side, then hit Run (F8). It should display a checkbox in the upper-left with show/hide functionality.
var viewer = new Cesium.Viewer('cesiumContainer');
// Create a typical CzmlDataSource.
var dataSource1 = new Cesium.CzmlDataSource();
dataSource1.load('../../SampleData/simple.czml');
// Add a checkbox at the top.
document.getElementById('toolbar').innerHTML =
'<label><input type="checkbox" id="showCheckbox" /> Show CZML</label>';
var checkbox = document.getElementById('showCheckbox');
checkbox.addEventListener('change', function() {
// Checkbox state changed.
if (checkbox.checked) {
// Show if not shown.
if (!viewer.dataSources.contains(dataSource1)) {
viewer.dataSources.add(dataSource1);
}
} else {
// Hide if currently shown.
if (viewer.dataSources.contains(dataSource1)) {
viewer.dataSources.remove(dataSource1);
}
}
}, false);
This code could be improved, for example it could be a "lazy load" where the dataSource.load does not get called until the first time it's shown. Also if a dataSource has been hidden a while, you have to consider at what point should you be saving memory by destroying the dataSource rather than continuing to hold onto it (triggering a new lazy load if it is later shown again).
as of now, show is a property of the data source, you can control it by accessing the property in dot or bracket notation:
https://cesiumjs.org/Cesium/Build/Documentation/CzmlDataSource.html#show
const src = new Cesium.CzmlDataSource();
src.show = false;

xna how to setup controls in game

I want to be able to go to options menu in the game I am developing and set up my controls.
It is a simple game of pong (for now) and the controls for each player are just up and down.
This is how I want the process to look like: I click SETUP CONTROLS, game displays the name of the control I am supposed to change and it waits, I click the button on keyboard that i want it to be changed to, game reads it and displays the next control I am supposed to change and so on until i change all controls.
I have found a way how to do that here and my code now looks basicly like this:
if (optionsBList.IsButtonClicked("SETUP CONTROLS")) //when i click the
//SETUP CONTROLS button
//in the options menu
{
KeyboardState currentKeyboardState = new KeyboardState();
waitingForKey = true;
while (waitingForKey)
{
if(currentKeyboardState.GetPressedKeys().Count() > 0)
{
player1.upkey = currentKeyboardState.GetPressedKeys()[0];
//the path for the key isn't player1.upkey, but lets say it is.
waitingForKey = false;
}
}
}
In this short code my goal is to change just one key. If I can make it change 1 key, changing more wont be a problem.
The problem is, I don't see why does my game stop responding when i click the SETUP CONTROLS button. I don't see an infinite loop here nor a memory leak.
Why is my game crashing and is there a better way to load controls in options menu?
If you saw the answer from the link you placed in your question, you would have noticed that he actually deleted the while loop and he made it an if statement.
Like Nico Schertler said : "while(waitingForKey) is your infinite loop. That loop blocks the game thread, so no further input is recognized."
Link to the answer from your link: https://stackoverflow.com/a/15935732/3239917
if (optionsBList.IsButtonClicked("SETUP CONTROLS")) //when i click the
//SETUP CONTROLS button
//in the options menu
{
KeyboardState currentKeyboardState = new KeyboardState();
waitingForKey = true;
if (waitingForKey )
{
if(currentKeyboardState.GetPressedKeys().Count() > 0)
{
player1.upkey = currentKeyboardState.GetPressedKeys()[0];
//the path for the key isn't player1.upkey, but lets say it is.
waitingForKey = false;
}
}
}

CRM form. Preset Field is not saved on after Clicking Save button

I am working on CRM 2011.
On Form_onLoad event I am presetting the value of a field.
mdg.PreSetField("address1_line1","Amsterdam");
but after clicking on save button my field address1_line1 is blank.
To check I put a alert on Form_onsave function.
alert("address =" + (Xrm.Page.getAttribute("address1_line1").getValue()));
In alert,I get the value of address1_line1 field but finally address1_line1 is blank.
mdg.PresetField function is as follows
mdg.PreSetField = function(attributeName, value) {
var attribute;
if (attributeName.setSubmitMode) {
attribute = attributeName;
}
else {
attribute = Xrm.Page.getAttribute(attributeName);
}
attribute.setSubmitMode('never');
attribute.setValue(value);
attribute.addOnChange(function() {
attribute.setSubmitMode('always');
});
};
I solved it..
in my custom mdg.PresetField function earlier code was
attribute.setSubmitMode('never');
I changed never to always and now it is working..
mdg.PreSetField("address1_line1","Amsterdam");
This code is not part of the CRM JavaScript API so I assume it's a custom library? Have you added this script to the list of webresources available on the form? Also make sure it comes before the script you are trying to use it in.

How to disable validators for a specific field from a button

I have a xpage that loads a Bootstrap modal window (see picture). I need to validate the data only the user pushes the 'Add New' button. I do not want the validators to run when 'Save and Continue' or 'Previous' buttons are pressed.
The modal dialog is a custom control used many times throughout the application. I cannot change the buttons to disable validators because most of the time I want to validate. The center content is stored in its own custom control.
My question is can I add code to the button to get a handle to each control, and set the disableValidators to true. I haven't been able to figure out how to do this. I have already tried computing the disableValidators but was totally unsuccessful. The fields are all bound to scoped variables.
I know that I can use clientside validation here, but the rest of the application uses server-side and I want to be consistent + this is a responsive app, and clientside on mobile is annoying.
Rather than adding code to button to and setting disableValidators for each control I would suggest the other way round. For each control set the required property only if user pushes 'Add New' button.
This blog post by Tommy Valand describes it in detail. The below function lets you test if a specific component triggered an update.
// Used to check which if a component triggered an update
function submittedBy( componentId ){
try {
var eventHandlerClientId = param.get( '$$xspsubmitid' );
var eventHandlerId = #RightBack( eventHandlerClientId, ':' );
var eventHandler = getComponent( eventHandlerId );
if( !eventHandler ){ return false; }
var parentComponent = eventHandler.getParent();
if( !parentComponent ){ return false; }
return ( parentComponent.getId() === componentId );
} catch( e ){ /*Debug.logException( e );*/ }
}
So if you want the validation to run only when the user clicks a specific 'Add New' button then write this in all the required-attributes:
return submittedBy('id-of-add-new-button')

How to "chain" modal dialogs in YUI 2?

I have a modal dialog box presented in Yahoo UI. The user selects a value from dialog "A", and then I want to present another modal dialog box to collect some more data in dialog "B".
I have been using the YAHOO.widget.Dialog successfully. The problem seems to be that you can't initiate dialog window "B" from the handler function of dialog "A". So, how can you programmatically launch a second dialog window after the user hits the "OK" button on the first ?
(I had tried to create an additional Listener for a field that is updated in dialog "A" to trigger dialog "B" but this doesn't work either.)
Thanks..
Check out the documentation: http://developer.yahoo.com/yui/container/dialog/#events. The following code should do the trick:
var firstDialog = new YAHOO.widget.Dialog('firstDialog', { postmethod: "manual" });
firstDialog.manualSubmitEvent.subscribe(function (type, args) {
var nextDialog = new YAHOO.widget.Dialog('nextDialog', { });
/* more configuration stuff... */
nextDialog.render();
nextDialog.show();
});
firstDialog.render();
firstDialog.show();
This handles when the form is to be submitted, which I think what you mean by selects a value, but if not let me know and I can give some help on that situation.

Resources