0
votes

In 2sxc module app I want to get values for "String Drop Down Values" from function or external web api and not with entered list of values.

Is this possible by default or can somebody give me some guides where to start to do this?

(EDIT/ADD) Is making Content Custom Input Type the only way, or there is some simpler way?

3
Try yourself first, google it, do some research and come back. - Enamul Hassan
I already try with google but the only possibility was 2sxc.org/en/blog/post/custom-input-type-advanced-dynamic-data so I asked is there some easier way - Jernej Pirc

3 Answers

1
votes

So basically your code is running inside Angular, which also has 2sxc4ng loaded. There are at least 3 ways to solve your problem.

  1. you can use the sxc object, which is the same as $2sxc(moduleId)
  2. you can use the iid
  3. you can just use $http, as it's already pre-loaded with the module-id in the headers

Using $http is pretty clear - and if you watch the wire, you'll see that the moduleid is already included in the headers.

to access iid or the sxc object, you need to put them as dependencies in this line .controller("FieldTemplate-String-Nn-Int-Json-List", function($scope, $filter, $modal, appId, debugState, eavAdminDialogs, $http) so you need .controller("FieldTemplate-String-Nn-Int-Json-List", function($scope, $filter, $modal, appId, debugState, eavAdminDialogs, $http, iid, sxc)

That should do it.

0
votes

Creating a custom input type is the only way as of now. Since many people are looking for something like this, it would be great if you would then sponsor/contribute it :)

0
votes

I attached sample app with little description.

download

All stuff is already described OK on this link: http://2sxc.org/en/blog/post/configurable-custom-input-type-dynamic-data-content

I just change this sample to use string and main code change is in angular controller and my code look like this:

        var url;
        var controlSettings = $scope.to.settings["string-nn-json-list"];
        if (controlSettings)  url = controlSettings.jsonUrl || null;
        // if null set default apiUrl
        if (url === null)     url = "http://www.mocky.io/v2/57aae03e120000be10739d3b";
        $http({
            method: 'GET',
            url: url,
            headers: {
                'TabId': undefined,
                'Pragma' : undefined,
                'RequestVerificationToken' : undefined,
                'Cache-Control' : undefined,
                'Debugging-Hint' : undefined,
                'ContentBlockId' : undefined,
                'ModuleId' : undefined,
            }
        }).then(function successCallback(response) {
            $scope.json_list_data = response.data;
        });

For external json api data I use this : http://www.mocky.io/v2/57aae03e120000be10739d3b created on www.mocky.io and this is the default jsonUrl for "string-nn-json-list". You can change this url in field settings.


EDIT(1)

I trying get moduleId with help of iid into controller but with no luck..

(function() {
    "use strict";
    angular.module("nnStringFromIntJsonData", [])
        .config(function(formlyConfigProvider, defaultFieldWrappers) {
        })
        .controller("FieldTemplate-String-Nn-Int-Json-List", function($scope, $filter, $modal, appId, debugState, eavAdminDialogs, $http) {
            // What to change in this code
            // that I can get iid (moduleId) in this part of code?
            debugger;
        })
        .run(
            function($templateCache) {
            })
})();

What I must change (add) to this code that iid is accessible?


EDIT(2)

One way but with lost of security (I use only for read not important data) is that way you remove Api controller attributes :

[DnnModuleAuthorize] and [ValidateAntiForgeryToken] and leave only [HttpGet]

and when calling from custom input type controller use something like :

var url = "/DesktopModules/2sxc/API/app-api/{ControllerName}/{MethodName}";
$http.get(url).then(function successCallback(response) {
    $scope.json_list_data = response.data;
});

I realy don't know what I am doing... It seems that more I learn less I know :-( and code with try/error system to get something partly usible...