Using a trigger to set pdf title to metadata value

Hey all,


I have an asset builder creating pdfs with a trigger to set attribute value of the title to some metadata that users select when building the asset.



The trigger is fine but the metadata keywords %asset_metadata_Fieldname% don't print the metadata; the pdf's title just becomes the keyword.



Is it possible to set attribute value to a metadata value?



I am on 3.18.11.

I am slightly confused what you are after here. What is the reason for the trigger in this situation?


What kind of metadata field is this that you are letting users pick from? A select menu?



If this is the case, just let them choose from the select menu, and automatically populate the title attribute field with that value. You could hide the title field with css, and then use javascript to set the value of the hidden title attribute to what the user just selected from the metadata field drop down.



Something like the following jQuery should do the trick:


    $('select').change(function() {
    	var meta_val = $('select option:selected').text();
    	$('#title_field').val(meta_val);
    });

That was my original idea but my javascript skills just couldn't work out how to do it. I tried using your code and replacing the bits that I thought would need to be replaced but it didn't work. :frowning:


What I want is for pdfs titles to be a combination of a select option and a metadata date. So the end result is Option 14 February 2009. Perhaps the date selects make the javascript too hard, that's why I thought maybe I could just use triggers to set the two metadata values to the title.

[quote]
That was my original idea but my javascript skills just couldn't work out how to do it. I tried using your code and replacing the bits that I thought would need to be replaced but it didn't work. :frowning:

[/quote]



Take a look at this file, it will show you a working example: [attachment=418:jQuery Test.html]
jQuery Test.html (846 Bytes)

Yes, that certainly works with a standard matrix select! :slight_smile:


However I think it might not be possible to do this with the datetime metadata boxes because they contain [] in the id which don't seem to play well in javascript. Your script which works great on my standard selector doesn't work when the id is metadata_field_date_15525_datetimevalue[m].

[quote]
Your script which works great on my standard selector doesn’t work when the id is metadata_field_date_15525_datetimevalue[m].

[/quote]



My selector was just an example. You can still use my method, but you need to traverse the DOM from a parent down to the child to target that element. Look at: http://docs.jquery.com/Selectors/nthChild#index



So, you would be wrapping a parent div around that metadata field keyword, then creating your selector to choose which child of the select you want is:


    var child_sel1 = $('#parent select:nth-child(1)');
    var child_sel2 = $('#parent select:nth-child(2)');
    
    child_sel2.change(function() {
    			var meta_val = $('#parent select:nth-child(2) option:selected').text();
    			$('#test').val(meta_val);
    });


If you are not able to get this working, could you provide me with the full source of your page?

Okay, if anyone is wanting to grab all the selected items in a series of dropdowns and put them together to title a file or something here is the jquery I used. Just replace pdf_file_0_204 with whatever the id of your field is.

    
    $("select").change(function () {
          var str = "";
          $("select option:selected").each(function () {
                str += $(this).text() + " ";
              });
          $("#pdf_file_0_204").val(str);
        })
        .trigger('change');
    

I got it mostly from the jquery page on selectors but changed the .text to .val.



Lots of thanks to Nic for his encouragement or I would have given up two days ago. :slight_smile: