Angularjs: prefill search field in Cloudinary upload widget









up vote
0
down vote

favorite












I'm integrating the cloudinary upload widget v2.0 into my angular app. To achieve this, I've created a service (to call some backend Cloudinary calls) and a directive (to link the upload widget to specific buttons).



Everything works fine until now, but I want to add an extra feature: The search field in the "google search" tab of the upload widget should be prefilled (based on what the user selected on the page).



I'm wondering how I can easily access this search field from my angular directive to update the value, while the upload widget isn't made in angular.



I already tried to use angular.element and find the search field based on some classes, but this doesn't seem to work.



$scope.uploadWidgetSearchField = angular.element($document[0].querySelector(".text-field.search-input"));
$scope.uploadWidgetSearchField.val("TEST VALUE"); // Test 1
$scope.uploadWidgetSearchField.replaceWith("<h2>TEST</h2>"); // Test 2


Service



angular.module('cloudinaryModule', [
'cloudinary',
'gimmi.config'
])
.provider('cloudinaryService', ['CONFIG', function(CONFIG)
var _self = this;
/** Set default options for Cloudinary upload widget.
* All options can be found at: https://cloudinary.com/documentation/upload_widget#cloudinary_openuploadwidget_options_resultcallback
*/
var widgetOptions =
sources: ['local', 'image_search', 'url'],
defaultSource: 'image_search',
resourceType: 'image',
multiple: false,
theme: "minimal",
showPoweredBy: false, //Note: Supported only for paid Cloudinary accounts and requires some time for cache expiration.
showAdvancedOptions: false,
showCompletedButton: false
;

_self.setOption = function (key, value)
widgetOptions[key] = value;
return _self;

_self.$get = ['$http', function($http)
var clsrv = ;

/** Get a signature for a signed upload to Cloudinary */
clsrv.getSignature = function (callback, params_to_sign)
$http.post(CONFIG.apiUrl + '/api/images/signature', params_to_sign)
.then((results) =>
var signature = results.data;
callback(signature);
);


/**
* Create a cloudinary upload widget
* @function createWidget
* @param String publicId A dynamically chosen publicId
* @param function callback A callback function with arguments error and results to handle events in the upload widget
* @return CloudinaryUploadWidget
* */
clsrv.createWidget = function(publicId, callback)
if (publicId)
widgetOptions.publicId = publicId;

widgetOptions.uploadSignature = clsrv.getSignature;
return cloudinary.createUploadWidget(widgetOptions, callback);


return clsrv;
];
]);


Directive



angular.module('cloudinaryModule')
.directive('clUpload', ['cloudinaryService', function (cloudinaryService)
return
restrict: 'AE',
replace: false,
scope:
searchTerm: '@',
publicId: '@',
imageResult: '=',
onImageUpload: '&',
onCancel: '&'
,
link: function ($scope, $element, $attrs)
/** Create the upload widget on loading the directive */
var widget = cloudinaryService.createWidget($scope.publicId, function (error, result)
if (result && result.event === "success")
var uploadedImage =
public_id: result.info.public_id,
version: result.info.version
;
if ($scope.imageResult)
$scope.$apply(function()
$scope.imageResult = uploadedImage;
);

if ($scope.onImageUpload)
$scope.$apply($scope.onImageUpload(uploadedImage));

console.log("Uploaded image:", $scope.imageResult);
widget.close( quiet: true );
else if (error)
console.error(error);
if ($scope.onCancel)
$scope.$apply($scope.onCancel(error));


);

/** On click on element: open the widget */
$element.on('click', function ()
widget.open();
);


])









share|improve this question



























    up vote
    0
    down vote

    favorite












    I'm integrating the cloudinary upload widget v2.0 into my angular app. To achieve this, I've created a service (to call some backend Cloudinary calls) and a directive (to link the upload widget to specific buttons).



    Everything works fine until now, but I want to add an extra feature: The search field in the "google search" tab of the upload widget should be prefilled (based on what the user selected on the page).



    I'm wondering how I can easily access this search field from my angular directive to update the value, while the upload widget isn't made in angular.



    I already tried to use angular.element and find the search field based on some classes, but this doesn't seem to work.



    $scope.uploadWidgetSearchField = angular.element($document[0].querySelector(".text-field.search-input"));
    $scope.uploadWidgetSearchField.val("TEST VALUE"); // Test 1
    $scope.uploadWidgetSearchField.replaceWith("<h2>TEST</h2>"); // Test 2


    Service



    angular.module('cloudinaryModule', [
    'cloudinary',
    'gimmi.config'
    ])
    .provider('cloudinaryService', ['CONFIG', function(CONFIG)
    var _self = this;
    /** Set default options for Cloudinary upload widget.
    * All options can be found at: https://cloudinary.com/documentation/upload_widget#cloudinary_openuploadwidget_options_resultcallback
    */
    var widgetOptions =
    sources: ['local', 'image_search', 'url'],
    defaultSource: 'image_search',
    resourceType: 'image',
    multiple: false,
    theme: "minimal",
    showPoweredBy: false, //Note: Supported only for paid Cloudinary accounts and requires some time for cache expiration.
    showAdvancedOptions: false,
    showCompletedButton: false
    ;

    _self.setOption = function (key, value)
    widgetOptions[key] = value;
    return _self;

    _self.$get = ['$http', function($http)
    var clsrv = ;

    /** Get a signature for a signed upload to Cloudinary */
    clsrv.getSignature = function (callback, params_to_sign)
    $http.post(CONFIG.apiUrl + '/api/images/signature', params_to_sign)
    .then((results) =>
    var signature = results.data;
    callback(signature);
    );


    /**
    * Create a cloudinary upload widget
    * @function createWidget
    * @param String publicId A dynamically chosen publicId
    * @param function callback A callback function with arguments error and results to handle events in the upload widget
    * @return CloudinaryUploadWidget
    * */
    clsrv.createWidget = function(publicId, callback)
    if (publicId)
    widgetOptions.publicId = publicId;

    widgetOptions.uploadSignature = clsrv.getSignature;
    return cloudinary.createUploadWidget(widgetOptions, callback);


    return clsrv;
    ];
    ]);


    Directive



    angular.module('cloudinaryModule')
    .directive('clUpload', ['cloudinaryService', function (cloudinaryService)
    return
    restrict: 'AE',
    replace: false,
    scope:
    searchTerm: '@',
    publicId: '@',
    imageResult: '=',
    onImageUpload: '&',
    onCancel: '&'
    ,
    link: function ($scope, $element, $attrs)
    /** Create the upload widget on loading the directive */
    var widget = cloudinaryService.createWidget($scope.publicId, function (error, result)
    if (result && result.event === "success")
    var uploadedImage =
    public_id: result.info.public_id,
    version: result.info.version
    ;
    if ($scope.imageResult)
    $scope.$apply(function()
    $scope.imageResult = uploadedImage;
    );

    if ($scope.onImageUpload)
    $scope.$apply($scope.onImageUpload(uploadedImage));

    console.log("Uploaded image:", $scope.imageResult);
    widget.close( quiet: true );
    else if (error)
    console.error(error);
    if ($scope.onCancel)
    $scope.$apply($scope.onCancel(error));


    );

    /** On click on element: open the widget */
    $element.on('click', function ()
    widget.open();
    );


    ])









    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm integrating the cloudinary upload widget v2.0 into my angular app. To achieve this, I've created a service (to call some backend Cloudinary calls) and a directive (to link the upload widget to specific buttons).



      Everything works fine until now, but I want to add an extra feature: The search field in the "google search" tab of the upload widget should be prefilled (based on what the user selected on the page).



      I'm wondering how I can easily access this search field from my angular directive to update the value, while the upload widget isn't made in angular.



      I already tried to use angular.element and find the search field based on some classes, but this doesn't seem to work.



      $scope.uploadWidgetSearchField = angular.element($document[0].querySelector(".text-field.search-input"));
      $scope.uploadWidgetSearchField.val("TEST VALUE"); // Test 1
      $scope.uploadWidgetSearchField.replaceWith("<h2>TEST</h2>"); // Test 2


      Service



      angular.module('cloudinaryModule', [
      'cloudinary',
      'gimmi.config'
      ])
      .provider('cloudinaryService', ['CONFIG', function(CONFIG)
      var _self = this;
      /** Set default options for Cloudinary upload widget.
      * All options can be found at: https://cloudinary.com/documentation/upload_widget#cloudinary_openuploadwidget_options_resultcallback
      */
      var widgetOptions =
      sources: ['local', 'image_search', 'url'],
      defaultSource: 'image_search',
      resourceType: 'image',
      multiple: false,
      theme: "minimal",
      showPoweredBy: false, //Note: Supported only for paid Cloudinary accounts and requires some time for cache expiration.
      showAdvancedOptions: false,
      showCompletedButton: false
      ;

      _self.setOption = function (key, value)
      widgetOptions[key] = value;
      return _self;

      _self.$get = ['$http', function($http)
      var clsrv = ;

      /** Get a signature for a signed upload to Cloudinary */
      clsrv.getSignature = function (callback, params_to_sign)
      $http.post(CONFIG.apiUrl + '/api/images/signature', params_to_sign)
      .then((results) =>
      var signature = results.data;
      callback(signature);
      );


      /**
      * Create a cloudinary upload widget
      * @function createWidget
      * @param String publicId A dynamically chosen publicId
      * @param function callback A callback function with arguments error and results to handle events in the upload widget
      * @return CloudinaryUploadWidget
      * */
      clsrv.createWidget = function(publicId, callback)
      if (publicId)
      widgetOptions.publicId = publicId;

      widgetOptions.uploadSignature = clsrv.getSignature;
      return cloudinary.createUploadWidget(widgetOptions, callback);


      return clsrv;
      ];
      ]);


      Directive



      angular.module('cloudinaryModule')
      .directive('clUpload', ['cloudinaryService', function (cloudinaryService)
      return
      restrict: 'AE',
      replace: false,
      scope:
      searchTerm: '@',
      publicId: '@',
      imageResult: '=',
      onImageUpload: '&',
      onCancel: '&'
      ,
      link: function ($scope, $element, $attrs)
      /** Create the upload widget on loading the directive */
      var widget = cloudinaryService.createWidget($scope.publicId, function (error, result)
      if (result && result.event === "success")
      var uploadedImage =
      public_id: result.info.public_id,
      version: result.info.version
      ;
      if ($scope.imageResult)
      $scope.$apply(function()
      $scope.imageResult = uploadedImage;
      );

      if ($scope.onImageUpload)
      $scope.$apply($scope.onImageUpload(uploadedImage));

      console.log("Uploaded image:", $scope.imageResult);
      widget.close( quiet: true );
      else if (error)
      console.error(error);
      if ($scope.onCancel)
      $scope.$apply($scope.onCancel(error));


      );

      /** On click on element: open the widget */
      $element.on('click', function ()
      widget.open();
      );


      ])









      share|improve this question















      I'm integrating the cloudinary upload widget v2.0 into my angular app. To achieve this, I've created a service (to call some backend Cloudinary calls) and a directive (to link the upload widget to specific buttons).



      Everything works fine until now, but I want to add an extra feature: The search field in the "google search" tab of the upload widget should be prefilled (based on what the user selected on the page).



      I'm wondering how I can easily access this search field from my angular directive to update the value, while the upload widget isn't made in angular.



      I already tried to use angular.element and find the search field based on some classes, but this doesn't seem to work.



      $scope.uploadWidgetSearchField = angular.element($document[0].querySelector(".text-field.search-input"));
      $scope.uploadWidgetSearchField.val("TEST VALUE"); // Test 1
      $scope.uploadWidgetSearchField.replaceWith("<h2>TEST</h2>"); // Test 2


      Service



      angular.module('cloudinaryModule', [
      'cloudinary',
      'gimmi.config'
      ])
      .provider('cloudinaryService', ['CONFIG', function(CONFIG)
      var _self = this;
      /** Set default options for Cloudinary upload widget.
      * All options can be found at: https://cloudinary.com/documentation/upload_widget#cloudinary_openuploadwidget_options_resultcallback
      */
      var widgetOptions =
      sources: ['local', 'image_search', 'url'],
      defaultSource: 'image_search',
      resourceType: 'image',
      multiple: false,
      theme: "minimal",
      showPoweredBy: false, //Note: Supported only for paid Cloudinary accounts and requires some time for cache expiration.
      showAdvancedOptions: false,
      showCompletedButton: false
      ;

      _self.setOption = function (key, value)
      widgetOptions[key] = value;
      return _self;

      _self.$get = ['$http', function($http)
      var clsrv = ;

      /** Get a signature for a signed upload to Cloudinary */
      clsrv.getSignature = function (callback, params_to_sign)
      $http.post(CONFIG.apiUrl + '/api/images/signature', params_to_sign)
      .then((results) =>
      var signature = results.data;
      callback(signature);
      );


      /**
      * Create a cloudinary upload widget
      * @function createWidget
      * @param String publicId A dynamically chosen publicId
      * @param function callback A callback function with arguments error and results to handle events in the upload widget
      * @return CloudinaryUploadWidget
      * */
      clsrv.createWidget = function(publicId, callback)
      if (publicId)
      widgetOptions.publicId = publicId;

      widgetOptions.uploadSignature = clsrv.getSignature;
      return cloudinary.createUploadWidget(widgetOptions, callback);


      return clsrv;
      ];
      ]);


      Directive



      angular.module('cloudinaryModule')
      .directive('clUpload', ['cloudinaryService', function (cloudinaryService)
      return
      restrict: 'AE',
      replace: false,
      scope:
      searchTerm: '@',
      publicId: '@',
      imageResult: '=',
      onImageUpload: '&',
      onCancel: '&'
      ,
      link: function ($scope, $element, $attrs)
      /** Create the upload widget on loading the directive */
      var widget = cloudinaryService.createWidget($scope.publicId, function (error, result)
      if (result && result.event === "success")
      var uploadedImage =
      public_id: result.info.public_id,
      version: result.info.version
      ;
      if ($scope.imageResult)
      $scope.$apply(function()
      $scope.imageResult = uploadedImage;
      );

      if ($scope.onImageUpload)
      $scope.$apply($scope.onImageUpload(uploadedImage));

      console.log("Uploaded image:", $scope.imageResult);
      widget.close( quiet: true );
      else if (error)
      console.error(error);
      if ($scope.onCancel)
      $scope.$apply($scope.onCancel(error));


      );

      /** On click on element: open the widget */
      $element.on('click', function ()
      widget.open();
      );


      ])






      angularjs cloudinary






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 at 19:15

























      asked Nov 11 at 13:45









      bits

      97112




      97112






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          There isn't a direct method to prefill the search field. This is something that the user will need to fill directly.






          share|improve this answer




















          • Ok, so Cloudinary doesn't support this feature. But I guess it should be possible with angular or jquery?
            – bits
            Nov 14 at 22:34










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53249369%2fangularjs-prefill-search-field-in-cloudinary-upload-widget%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          There isn't a direct method to prefill the search field. This is something that the user will need to fill directly.






          share|improve this answer




















          • Ok, so Cloudinary doesn't support this feature. But I guess it should be possible with angular or jquery?
            – bits
            Nov 14 at 22:34














          up vote
          0
          down vote













          There isn't a direct method to prefill the search field. This is something that the user will need to fill directly.






          share|improve this answer




















          • Ok, so Cloudinary doesn't support this feature. But I guess it should be possible with angular or jquery?
            – bits
            Nov 14 at 22:34












          up vote
          0
          down vote










          up vote
          0
          down vote









          There isn't a direct method to prefill the search field. This is something that the user will need to fill directly.






          share|improve this answer












          There isn't a direct method to prefill the search field. This is something that the user will need to fill directly.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 at 10:54









          rcstraus

          30411




          30411











          • Ok, so Cloudinary doesn't support this feature. But I guess it should be possible with angular or jquery?
            – bits
            Nov 14 at 22:34
















          • Ok, so Cloudinary doesn't support this feature. But I guess it should be possible with angular or jquery?
            – bits
            Nov 14 at 22:34















          Ok, so Cloudinary doesn't support this feature. But I guess it should be possible with angular or jquery?
          – bits
          Nov 14 at 22:34




          Ok, so Cloudinary doesn't support this feature. But I guess it should be possible with angular or jquery?
          – bits
          Nov 14 at 22:34

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53249369%2fangularjs-prefill-search-field-in-cloudinary-upload-widget%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Barbados

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3