0

I have to customize an announcement list new and edit form.

In the form is there is a Picture Colum. But I don’t want the user to go first to a picture library, upload the picture, copy the picture url and fill in the url in the announcement list form.

In the Internet I found this helping jScript (http://spimagefieldupload.codeplex.com/).

//If the link is clicked, show the existing RteUploadDialog.aspx page as a popup

      var dialog = {url: SP.Utilities.Utility.getLayoutsPageUrl("RteUploadDialog.aspx") + "?LCID=" + SP.Res.lcid + "&Dialog=UploadImage&UseDivDialog=true&Source=" + encodeURIComponent(window.location),
            allowMaximize: true,
            showClose: true,
            width: 500,
            height: 160,
            dialogReturnValueCallback: function (success, html) {
                if (success) {
                    //Gets the picture's url from the popup, shows it and hides the links
                    var $emptyPanel = jQuery("#" + selectorId + "_EmptyPanel");
                    var $assetSelectedPanel = jQuery("#" + selectorId + "_AssetSelectedPanel");
                    var $imageFieldDisplay = jQuery("#" + selectorId + "_ImageFieldDisplay");
                    $imageFieldDisplay.html(html);
                    $emptyPanel.css("display", "none");
                    $assetSelectedPanel.css("display", "inline");
                }
            }
        };
        thisDialog = SP.UI.ModalDialog.showModalDialog(dialog);

But how i can change the script (dialogReturnValueCallback: function) so that the picture url and the picture name is stored in jScript Variables in the form. So I can write I back in the form fileds.

Thanks for your help

0

I used a plain single line textbox named "Feature Image" to achieve this. I also added in a "Test Link" hyperlink for users to verify the image was uploaded correctly. Code below:

 //If the link is clicked, show the existing RteUploadDialog.aspx page as a popup
    var dialog = {
        url: SP.Utilities.Utility.getLayoutsPageUrl("RteUploadDialog.aspx") + "?LCID=" + SP.Res.lcid + "&Dialog=UploadImage&UseDivDialog=true&Source=" + encodeURIComponent(window.location),
        allowMaximize: true,
        showClose: true,
        width: 500,
        height: 160,
        dialogReturnValueCallback: function (success, html) {
            if (success) {
                //Gets the picture's url from the popup, shows it and hides the links
                $("input[Title$='Feature Image']").val(thisSite + "/" + html.substring(11,html.indexOf("alt") - 2));
                var tagId = $("input[Title$='Feature Image']").attr("id");
                var testLinkDiv = "<div id=\"testFeaturedImage\" Title=\"Test Image\" style=\"color:black; float:right\"><a href=\"" +
                    "javascript:TestURL('" + tagId + "');\">Test Image Link" +"</a></div>";
                $(testLinkDiv).insertAfter($('td.ms-formlabel:contains("Feature Image")').parent('tr'));
            }
        }
    };

    $("input[Title$='Feature Image']").focus(function(){
        $('#testFeaturedImage').hide();
        if($(this).val() == ""){
            //Featured Image is blank, enable click to add
            thisDialog = SP.UI.ModalDialog.showModalDialog(dialog);
        }
        else{
            var imgIndex = -1;
            var tagId = $(this).attr("id");
            //A value exists in the featured image textbox.  Allow user to test
            var testLinkDiv = "<div id=\"testFeaturedImage\" Title=\"Test Image\" style=\"color:black; float:right\"><a href=\"" +
                "javascript:TestURL('" + tagId + "');\">Test Image Link" +"</a></div>";
            $(testLinkDiv).insertAfter($('td.ms-formlabel:contains("Feature Image")').parent('tr'));
        }
    }).blur(function(){
        if($(this).val() == ""){
            $('#testFeaturedImage').hide();
        }
    });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.