Specify Angular Schema Form Select drop down options using scope - angularjs

I've been looking at using Angular Schema Form to define all my forms for my project but one thing that stood out to me massively is that when we define a select/drop-down element, the values have to be specified then and there in the JSON. This doesn't strike me as very flexible as I want these values to be retrieved from my Angular controller/factory as they are currently available on the scope.
I've done quite a bit of searching on how to get round this but haven't found a definitive solution or anything that worked for me so I decided to try to extend the Select myself and add a mapping to the schemaFormDecoratorsProvider.
I have followed the documentation for Extending Schema Form, and now have an HTML snippet which defines my Select control and this is being rendered when I define it in my JSON schema. What I want to be able to do is to specify the ng-options attribute either in part as a whole via the JSON schema. I have tried to do this but nothing seems to result in the select options being rendered.
Here is part of my select control:
<select ng-model="$$value$$"
ng-model-options="form.ngModelOptions"
sf-changed="form"
schema-validate="form"
ng-options="item.value as item.name for item in form.titleMap"
ng-disabled="form.readonly">
</select>
Where ng-options is defined, I want to be able to either specify titleMap in my JSON and it be resolved to an object on my scope or I can pass the name of the collection in my JSON and then pass that in where form.titleMap currently sits.
Anybody had any experience doing this? To me is seems like a fairly reasonable requirement but can't find much help on the web about it.
Many thanks.

There are add-ons designed to support dynamic data selection, the library has no preference and leaves it up to the developer to select the most appropriate for their needs, however I built the Material Design decorator to include the capabilities of angular-schema-form-external-options in the decorator so the add-on is not needed. The bootstrap decorator does not have this capability at this stage.
The angular-schema-form-external-options library is basic but covers most requirements for simple dynamic drop down data population
The angular-schema-form-dynamic-select is a more robust and feature full option with a variety of configurable options.

Related

Accessing CustomFieldDefinition metadata via tooling api

So, I've been attempting to gather picklist dependencies per Opportunity record type for my lightning components. I have been able to retrieve Standard Field dependencies by RecordType, but it the Tooling API will not return the custom field dependencies. Standard calls and queries will not work either, as they state that the field has no controlling value or dependency.
Given this information I suspected that there was a table that is hidden somewhere that contains the keys for the RecordType and FieldDefinition, hopefully with a nested Metadata object.
I found an Id in one of the parameters in the setup menu for a Record Type and Id.getSObjectType() on it. The table name is CustomFieldDefinition. However, it is not accessible via SOQL or the Tooling API.
Has anyone accessed this table? Or has anyone been able to retrieve the field-record type picklist dependencies on custom fields AND standard fields?Tooling API ResponseDebug Log with SObject Name
I think you're doing it wrong.
"Controlling field" would be another picklist or a checkbox for example, something you change during same edit action. If you have dependency to record type - in that sense it's not a controlling field. Sure, you change record type and picklist changes - but really everything would change, it should be a different page layout (different fields shown, marked readonly/required etc). There's a reason that record type change is not done on normal edit screen, you do it by clicking special link on detail view and then everything "explodes".
Have a look at "User Interface API" - set of tools meant to help your custom app (mobile? desktop?) steal recreate a normal page layout. This one might be especially useful: https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_resources_picklist_values_collection.htm
There's even a Trailhead: https://trailhead.salesforce.com/en/content/learn/modules/user-interface-api (skim through whole set but especially read last module)
And since you mentioned Lightning Components - are you aware of these ready tools:
https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.reference_ui_api
getPicklistValuesByRecordType
https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.reference_generate_record_input_create
or maybe you don't have to code it all and stuff like <lightning-record-edit-form> with recordtypeid passed to it will solve all your problems
Have a look, if I didn't give you a working solution then at least you have some keywords to Google around. If you're still stuck - try to post a code sample as new question?

Apache Zeppelin: get built in table data in code

Apache Zeppelin 0.8.0 allow to modify data in cells in built-in table.
I assume new values are linked to some variable inside angular scope.
How can I find out what is the name of this variable, so I'd be able to read it in the next paragraph using zeppelin context:
z.angular("tableData??")
Is it possible to get all variables available in zeppelin context?
Any suggestions appreciated.
As for now I've found an indirect way of doing it. It's a bit tacky way, so I'm still looking for better solution.
In the example below I'm implementing simplified scenario, where I just need to remove selected lines.
There are few features I'm using:
Table grid allow to incorporate html into the cells.
%spark.sql
select product, price, '%html <input class="input_data" ... />' from table_a
Unfortunately it's impossible to use %angular inside table, so I've requested this feature: ZEPPELIN-3068
Using this feature we can add another column into the table with any html element (checkbox, input field or external link). I can use selected variables from table to generate unique ids.
It can even be a small form with POST request to web-service that will immediately perform requested changes.
Next paragraph will contain javascript that read data from html elements we've created above and store it in zeppelin context.
%angular
document.getElementsByClassName("input_data")
ps. if anyone need code, I can add full script.

Breezejs + Angular - How to Properly Map Database Property Names?

I have a working and reusable custom <select> directive that populates via ng-options, here is the snippet:
ng-options="datum.name for datum in data track by datum.id"
This works as intended when I use a local test JSON file to populate it as I can define the name and id properties manually. When using Breezejs (which is properly pulling back data as expected), the database has Product and DeviceID instead of the desired name and id properties.
I want to be able to pull the data, but map Product and DeviceID to name and id as doing so ensures the goal of reusability of my custom <select> directive. Many different entities will need to map to name and id, so this is important for reusability.
How do I accomplish this? I've looked at Mapping JSON to entities and JsonResultsAdapter thinking this is the right direction. Unfortunately, these examples seem to be missing what I need (unless I'm missing something).
Are there other solutions or ways to tackle this problem? Is there a best practice way of doing this using breezejs? Thank you in advance for any light you can shed.
*Found a solution
I was using a custom directive like so (but I now add the options-map attribute):
<sel-select-box
id="selectBoxDevice1"
select-size="10"
options-map="datum.Product for datum in data track by datum.DeviceID"
service-in="deviceSearchDataService"
service-in-watch="getDevice1Matches"
service-in-restore="getDevice1Selection"
service-out="deviceSearchDataService"
service-out-send="updateDevice1Selection">
</sel-select-box>
Then in my reusable <select> I reference the {{optionsMap}} like so:;
<select
class="form-control"
ng-model="selected"
ng-change="onChange()"
ng-click="onClick()"
ng-options="{{optionsMap}}"
data-ng-attr-size="{{selectSize}}">
</select>
As a result I can now use the numerous custom <sel-select-box> directives and simply add the proper map string that the <select>'s ng-options utilizes.
I'm super stoked this works and that it achieves the flexibility I desire, but I'm still open to improved ideas and/or suggestions.
Have you looked at a custom NamingConvention? The NC is dedicated to the business of mapping between client-side and server-side entity property names

UI Bootstrap's typeahead refuses to iterate through object

According to docs found on official ui-bootstrap, typeahead directive "uses the same, flexible syntax as the select directive"
But unfortunatelly it seems that typeahead directive refuses to iterate through object sources using the following list of syntaxes supported by select
for object data sources:
label for (key , value) in object
select as label for (key , value) in object
label group by group for (key, value) in object
select as label group by group for (key, value) in object
I think that UI-Bootstrap's ui-bootstrap-tpls-0.4.0.js need to be edited (somewhere around line 2749) to allow this kind of functionality
So my question is what is angular and ui-bootstrap-friendly approach to implementing this functionality, (I can do it by replacing the .length with something that is more object-friendly, but I guess that there are lot more better ways of supporting the select object datasource syntax, than I can provide)
Thank you,
Indeed, the current implementation of the typeahead directive from http://angular-ui.github.io/bootstrap/ works only on sources that are arrays, so there is no way to iterate over objects. I've opened an issue to clarify this in the documentation:
https://github.com/angular-ui/bootstrap/issues/715
The culprit is this piece of code, really:
https://github.com/angular-ui/bootstrap/blob/master/src/typeahead/typeahead.js#L109-L115
While switching it to the angular.forEach would make the situation better, the main problem is that built-in AngularJS filters won't work on objects... So you would have to write your own matching logic as well. This is why I've decided to drop support for the (key, value) syntax.
Currently your best option is to convert your object to an array.
So I'm going to update the docs to make it clear what is supported and what is not. But if you can see a perfect solution here, feel free to send a pull request!

Cognos : Persisting Checkbox state across Multiple Pages

On the Cognos Report Results Page, we need to have a checkbox for each row.
The checkbox is designed using HTMLITEM tag.
However, the problem we face is that the state of the checkbox (checked or unchecked) is not persisted when we go to the next page/previous page.
I am very new to Cognos and I need to know if there is a way to do this.
I am fairly good at JAVAScripting and JSP, but since we only have access to HTML elements and not JSP Tags (Cognos uses CGI anyways), I cannot get the request object.
If there is some way to retrieve the request objects parameters of previous submit(previous page), that would help in solving the issue to a large extent, I feel.
Jonas
There isn't really enough information on what your end goal is to be able to assist you with this properly. There are a few ways that spring to mind that would allow you to use JS on the report to remember previously checked items, but there may be a much better way to do this depending on your requirements.
Without having more details, the first thing that leaps to mind is simply having some JavaScript set and unset cookie values on check/uncheck on the checkbox.
Note, there could be a variety of other ways to work this, including upping the number of visible rows per page, etc...
You can create a dataitem in a query where you can determine whether your checkbox should be checked or not. In the design of your list on the report page you can render a HTMLItem within the list, and base the HTMLItem on a DataItem. Your HTML must than be something like
<input type="checkbox" value="""+ [DataItemValueToPass] + """ " + [DataItemCheckedOrNot] ></input>

Resources